﻿Imports ADOEntity
Imports ADOEntityKYC
Imports ADOEntityAMLO102
Imports System.Data

Partial Class AMLO_Amlo1_02
    Inherits Web.UI.BasePage

#Region " Variable Gobal "
    Private Const strRptType As String = "2"
    Dim mCustomerEntitys As KYCEntities
    Dim BranchEntity As userEntities
    Dim AMLOEntity As AMLO102Entities

    Dim clsDataTable As clsLINQToDataTable
    Dim clsQry As clsDatabase
    Dim clsFormatDate As clsDateFormat
    Dim clsSessionMenuRight As clsSessionMenuRight
    Dim clsMasterDropDown As clsMasterDropDown
    Dim clsCurrencyTotext As clsMoney
    Dim tblCustomer As IList(Of MCUSTOMER) = Nothing
    Dim tblAmloDetail As IList(Of AMLODETAIL102) = Nothing

    Dim dsAMLO As DataSet
    Dim strStatus As String
    Dim strRptSeq As String
    Dim blnStatusComplete As Boolean
    Dim strMsg As String = ""
    Dim strError As String = ""

    Dim intBeforeItemIndex As Integer

    Private Enum enmTabClick
        tab1 = 1
        tab2 = 2
        tab3 = 3
    End Enum

    Private Enum enmPartSearch
        part1 = 1
        part2 = 2
    End Enum

#End Region

#Region " Even Page "

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        blnStatusComplete = False
        chkIsLogin()
        strStatus = Request.QueryString("Status")
        strRptSeq = Request.QueryString("code")
        btnSearchData.Attributes.Add("onclick", "NoDoubleSubmit();")
        btnSearchData0.Attributes.Add("onclick", "NoDoubleSubmit2();")

        If Not IsPostBack Then
           dsAMLO = New DataSet
            AMLOEntity = New AMLO102Entities
            clsMasterDropDown = New clsMasterDropDown
            CreateControlMP() 'เป็นการเซ็ตว่าเป็นปปง อะไร
            SetClickTab(enmTabClick.tab1) 'เป็นการเซ็ตค่าเริ่มต้นให้อยู่ที่ tab 1
            setDefaultEnable() 'เป็นการเซ็ต ว่าเปิดใช้งานหรือไม่
            Try
                LoadDataToDropdown()
                'setBranch()
                setDefaultValue() 'เป็นการเซ็ตค่า เริ่มต้น
                If (strStatus = "Add") Then
                    createStructure() 'สร้าง temp table rrptDetail
                ElseIf (strStatus = "Edit") Then
                    dsAMLO = New DataSet
                    CreateControlMP()
                    SetClickTab(enmTabClick.tab1)
                    'setBranch()
                    loadData(strRptSeq)
                    setDefaultEnable()
                End If
                If Not dsAMLO.Tables("AmloDetail").Rows.Count = 0 Then
                    grdShowCountry.DataSource = dsAMLO.Tables("AmloDetail")
                    grdShowCountry.DataBind()
                Else
                    grdShowCountry.DataSource = dsAMLO.Tables("AmloDetail")
                    grdShowCountry.DataBind()
                End If
                blnStatusComplete = True
            Catch ex As Exception
                blnStatusComplete = False
                strError = "Error Message :" & If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
            End Try
            If Not (blnStatusComplete) Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                   UpdatePanel1.GetType(), _
                                                                   "clientScript", _
                                                                   "alert('" + strError.Replace("'", "") + "')", _
                                                                   True)
            End If
            AMLOEntity = Nothing
            clsDataTable = Nothing
        Else
            dsAMLO = Session("ds")

        End If
    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("ds") = dsAMLO
    End Sub

#End Region

#Region " Even Button "

#Region " Image Button Tab"

    Protected Sub ibtnTab1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnTab1.Click
        SetClickTab(enmTabClick.tab1)
    End Sub

    Protected Sub ibtnTab2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnTab2.Click
        SetClickTab(enmTabClick.tab2)
    End Sub

    Protected Sub ibtnTab3_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnTab3.Click
        SetClickTab(enmTabClick.tab3)
    End Sub

#End Region

#Region " Button "

    Protected Sub btnSearchData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchData.Click
         blnStatusComplete = False
        Try

            If Not (searchCustomer(txtUniqueID.Text.Trim, enmPartSearch.part1)) Then
                clearDataPart(enmPartSearch.part1)
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                  UpdatePanel1.GetType(), _
                                                                  "clientScript", _
                                                                  "alert('" + "ไม่พบข้อมูลในระบบ" + "')", _
                                                                  True)

            End If

            blnStatusComplete = True
        Catch ex As Exception
            blnStatusComplete = False
            strError = "Error Message :" & If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
        End Try
        If Not (blnStatusComplete) Then
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                               UpdatePanel1.GetType(), _
                                                               "clientScript", _
                                                               "alert('" + strError.Replace("'", "") + "')", _
                                                               True)
        End If
    End Sub

    Private Function searchCustomer(ByVal strUnique As String, ByVal UseSearchPart As enmPartSearch) As Boolean
        Dim blnChkHaveUseas As Boolean = True
        Dim dtbCusAmlo As DataTable = New DataTable
        Dim dtbMCus As DataTable = New DataTable
        Dim clsVariable As clsVariable
        Dim cltParameter As New Collection
        mCustomerEntitys = New KYCEntities
        clsQry = New clsDatabase

        Try
            Dim strSql = "select * from " & System.Configuration.ConfigurationSettings.AppSettings("Tableviewcusamlo") & " where uniqueID = :prmUniqueID1 and rank = (select max(rank) from " & System.Configuration.ConfigurationSettings.AppSettings("Tableviewcusamlo") & " where uniqueID = :prmUniqueID2 )"

            clsVariable = New clsVariable
            clsVariable.nameColumn = "prmUniqueID1"
            clsVariable.valueColumn = strUnique
            cltParameter.Add(clsVariable)

            clsVariable = New clsVariable
            clsVariable.nameColumn = "prmUniqueID2"
            clsVariable.valueColumn = strUnique
            cltParameter.Add(clsVariable)


            dtbCusAmlo = clsQry.QueryDataTableAddParameter(strSql, cltParameter)
            cltParameter.Clear()
            If Not (dtbCusAmlo.Rows.Count = 0) Then

                SetDataCustomerpart1(UseSearchPart, dtCusAmlo:=dtbCusAmlo)
            Else
                clsQry = New clsDatabase
                Dim strSqlMCus = "SELECT mprefix.prefixth thprefix, mcustomer.thfirstname, mcustomer.thmidname, " _
               & " MCUSTOMER.THLASTNAME, MCUSTOMER.FORMALADDR, MCUSTOMER.FORMALPHONE1, " _
               & " MCUSTOMER.FORMALFAX, MCUSTOMER.WORKADDR, MCUSTOMER.WORKPHONE1, " _
               & " MCUSTOMER.WORKFAX, MCUSTOMER.CONTACTADDR, MCUSTOMER.CONTACTPHONE1, " _
               & " MCUSTOMER.CONTACTFAX " _
               & " FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMCUSTOMER") & " left join " & System.Configuration.ConfigurationSettings.AppSettings("TableMPREFIX") & " on mcustomer.thprefix = mprefix.prefixcode where UNIQUEID = :prmUniqueID"

                cltParameter = New Collection
                clsVariable = New clsVariable
                clsVariable.nameColumn = "prmUniqueID"
                clsVariable.valueColumn = strUnique
                cltParameter.Add(clsVariable)

                dtbMCus = clsQry.QueryDataTableAddParameter(strSqlMCus, cltParameter)
                If Not (dtbMCus.Rows.Count = 0) Then
                    SetDataCustomerpart1(UseSearchPart, tblmCus:=dtbMCus)
                Else
                    blnChkHaveUseas = False
                End If
            End If


        Catch ex As Exception
            Throw ex
        End Try
        clsQry = Nothing
        dtbCusAmlo = Nothing
        dtbMCus = Nothing
        clsVariable = Nothing
        cltParameter = Nothing
        mCustomerEntitys.Dispose()
        mCustomerEntitys = Nothing
        Return blnChkHaveUseas
    End Function

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        blnStatusComplete = False
        Try
            If (ChkDataPart2()) Then
                saveData()
                grdShowCountry.DataSource = dsAMLO.Tables("AmloDetail")
                grdShowCountry.DataBind()
                grdShowCountry.SelectedIndex = -1
                clearDataPart(enmPartSearch.part2)
                setbtnpart2("")
                blnStatusComplete = True

            End If

        Catch ex As Exception

            blnStatusComplete = False
            strError = "Error Message :" & If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
        End Try
        If Not (blnStatusComplete) Then
            If Not (strError = "") Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                              UpdatePanel1.GetType(), _
                                                                              "clientScript", _
                                                                              "alert('" + strError.Replace("'", "") + "')", _
                                                                              True)
            ElseIf Not (strMsg = "") Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                             UpdatePanel1.GetType(), _
                                                                             "clientScript", _
                                                                             "alert('" + strMsg + "')", _
                                                                             True)
            End If

        End If


    End Sub

    Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        blnStatusComplete = False
        Try
            If (ChkDataPart2()) Then
                updateData(hdfRptIdx.Value)
                grdShowCountry.DataSource = dsAMLO.Tables("AmloDetail")
                grdShowCountry.DataBind()
                clearDataPart(enmPartSearch.part2)
                grdShowCountry.SelectedIndex = -1
                setbtnpart2("")
                blnStatusComplete = True
            End If
        Catch ex As Exception
            blnStatusComplete = False
            strError = "Error Message :" & If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
        End Try

        If Not (strError = "") Then
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                          UpdatePanel1.GetType(), _
                                                                          "clientScript", _
                                                                          "alert('" + strError.Replace("'", "") + "')", _
                                                                          True)
        ElseIf Not (strMsg = "") Then
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                         UpdatePanel1.GetType(), _
                                                                         "clientScript", _
                                                                         "alert('" + strMsg + "')", _
                                                                         True)
        End If

    End Sub

    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
       blnStatusComplete = False
        Try
            Dim dr() As DataRow = dsAMLO.Tables("AmloDetail").Select("RPTIDX = " & hdfRptIdx.Value)
            dr(0).Delete()
            dsAMLO.AcceptChanges()

            grdShowCountry.DataSource = dsAMLO.Tables("AmloDetail")
            grdShowCountry.DataBind()

            grdShowCountry.SelectedIndex = -1


            clearDataPart(enmPartSearch.part2)
            btnAdd.Visible = True
            btnEdit.Visible = False
            btnDelete.Visible = False
            setbtnpart2("")
            blnStatusComplete = True
        Catch ex As Exception
            blnStatusComplete = False
            strError = "Error Message :" & If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
        End Try

        If Not (blnStatusComplete) Then
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                               UpdatePanel1.GetType(), _
                                                               "clientScript", _
                                                               "alert('" + strError.Replace("'", "") + "')", _
                                                               True)
        End If

    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        clsFormatDate = New clsDateFormat
        clsCurrencyTotext = New clsMoney
        clsSessionMenuRight = Session("ClsMenuRight")
        If ChkData() Then
            AMLOEntity = New AMLO102Entities
            Dim tblAmlo As AMLO102 = New AMLO102
            Dim tblAmloDetail As AMLODETAIL102 = Nothing
            Dim maxID As Integer = 0
            Dim MaxNo As Integer = 0
            Dim strMaxNo As String = ""
            AMLOEntity.Connection.Open()
            blnStatusComplete = False
            Dim strMsg As String = ""

            Using transaction As System.Data.Common.DbTransaction = AMLOEntity.Connection.BeginTransaction()
                Dim intRptSeq As Long = 0
                Try
                    If (strStatus = "Add") Then
                        maxID = (From tbl_RRpt In AMLOEntity.AMLO102 Select tbl_RRpt.RPTSEQ).Max
                        If (maxID = 0) Then
                            intRptSeq = 1
                        Else
                            intRptSeq = maxID + 1
                        End If
                        If (rdolIsComple.SelectedValue = 1) Then
                            MaxNo = (From tbl_amlo In AMLOEntity.AMLO102 Where tbl_amlo.RPTTYPE = strRptType And tbl_amlo.SOL_ID = clsSessionMenuRight.getSOL_ID And _
                                                             tbl_amlo.RPTYEAR = txtYear.Text.Trim Select tbl_amlo.RPTNO).Max
                            If (MaxNo = 0) Then
                                strMaxNo = "00000001"
                            Else
                                strMaxNo = (MaxNo + 1).ToString
                                If (strMaxNo.Length = 1) Then
                                    strMaxNo = "0000000" + strMaxNo
                                ElseIf (strMaxNo.Length = 2) Then
                                    strMaxNo = "000000" + strMaxNo
                                ElseIf (strMaxNo.Length = 3) Then
                                    strMaxNo = "00000" + strMaxNo
                                ElseIf (strMaxNo.Length = 4) Then
                                    strMaxNo = "0000" + strMaxNo
                                ElseIf (strMaxNo.Length = 5) Then
                                    strMaxNo = "000" + strMaxNo
                                ElseIf (strMaxNo.Length = 6) Then
                                    strMaxNo = "00" + strMaxNo
                                ElseIf (strMaxNo.Length = 7) Then
                                    strMaxNo = "0" + strMaxNo
                                ElseIf (strMaxNo.Length = 8) Then
                                    strMaxNo = strMaxNo
                                End If
                            End If
                        Else
                            strMaxNo = ""
                        End If


                        setTransaction(tblAmlo, intRptSeq, strMaxNo, rdolIsComple.SelectedValue)
                        SetDataFact(tblAmlo)
                        AMLOEntity.AddToAMLO102(tblAmlo)
                        setCustomerSave()
                        SetPartnerTrans(AMLOEntity, tblAmloDetail, intRptSeq)
                        maxID = Nothing
                        SaveLogPrint(3, strMaxNo)
                    ElseIf (strStatus = "Edit") Then
                        If (rdolIsComple.SelectedValue = 1) And (rdolIsComple.Enabled = True) Then
                            MaxNo = (From tbl_Amlo In AMLOEntity.AMLO102 Where tbl_Amlo.RPTTYPE = strRptType And tbl_Amlo.SOL_ID = clsSessionMenuRight.getSOL_ID And _
                                                            tbl_Amlo.RPTYEAR = txtYear.Text.Trim Select tbl_Amlo.RPTNO).Max
                            If (MaxNo = 0) Then
                                strMaxNo = "00000001"
                            Else
                                strMaxNo = (MaxNo + 1).ToString
                                If (strMaxNo.Length = 1) Then
                                    strMaxNo = "0000000" + strMaxNo
                                ElseIf (strMaxNo.Length = 2) Then
                                    strMaxNo = "000000" + strMaxNo
                                ElseIf (strMaxNo.Length = 3) Then
                                    strMaxNo = "00000" + strMaxNo
                                ElseIf (strMaxNo.Length = 4) Then
                                    strMaxNo = "0000" + strMaxNo
                                ElseIf (strMaxNo.Length = 5) Then
                                    strMaxNo = "000" + strMaxNo
                                ElseIf (strMaxNo.Length = 6) Then
                                    strMaxNo = "00" + strMaxNo
                                ElseIf (strMaxNo.Length = 7) Then
                                    strMaxNo = "0" + strMaxNo
                                ElseIf (strMaxNo.Length = 8) Then
                                    strMaxNo = strMaxNo
                                End If
                            End If
                        Else
                            strMaxNo = ""
                        End If
                        Dim qryToUpdateMaster = (From tbl_Master In AMLOEntity.AMLO102 Where tbl_Master.RPTSEQ = hdfRptSeq.Value).ToList
                        setTransaction(qryToUpdateMaster, strMaxNo)
                        SetDataFact_Edit(qryToUpdateMaster)

                        Dim qryToUpdateDetail = (From tbl_detail In AMLOEntity.AMLODETAIL102 Where tbl_detail.RPTSEQ = hdfRptSeq.Value).ToList
                        Dim qryTodelete = qryToUpdateDetail.Where(Function(f) f.RPTIDX <> 1)

                        For i As Integer = 0 To qryTodelete.Count - 1
                            AMLOEntity.DeleteObject(qryTodelete.Where(Function(f) f.RPTIDX <> 1)(i))
                        Next

                        setCustomer(qryToUpdateDetail.Where(Function(f) f.RPTIDX = 1).ToList)
                        SetPartnerTrans(AMLOEntity, tblAmloDetail, hdfRptSeq.Value)
                        SaveLogPrint(4, strMaxNo)
                    End If
                    AMLOEntity.SaveChanges()
                    transaction.Commit()
                    blnStatusComplete = True

                Catch ex As Exception
                    transaction.Rollback()
                    strError = If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
                    blnStatusComplete = False
                End Try
            End Using

            AMLOEntity = Nothing
            clsFormatDate = Nothing
            clsCurrencyTotext = Nothing
            tblAmlo = Nothing
            tblAmloDetail = Nothing
            clsSessionMenuRight = Nothing
            If (blnStatusComplete = True) Then
                If (rdolIsComple.SelectedValue = 1 And rdolIsComple.Enabled = True) Then
                    'ScriptManager.RegisterStartupScript(UpdatePanel1, _
                    '                                                        UpdatePanel1.GetType(), _
                    '                                                        "clientScript", _
                    '                                                        "alert('" + strMaxNo + "')", _
                    '                                                        True)
                    'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "message", _
                    '                               "alert('" + strMaxNo + "');location.href = 'SearchAmlo1_02.aspx';", True)
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "message", _
                                                "alert('" & "บันทึกข้อมูลเรียบร้อยแล้ว \n เลขที่ " & strMaxNo.ToString & "');location.href = 'SearchAmlo1_02.aspx';", True)
                Else
                    If (strStatus = "Add") Then
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "message", _
                                                                   "alert('" + "บันทึกข้อมูลเรียบร้อยแล้ว" + "');location.href = 'SearchAmlo1_02.aspx';", True)
                    Else

                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "message", _
                                                                      "alert('" + "แก้ไขข้อมูลเรียบร้อยแล้ว" + "');location.href = 'SearchAmlo1_02.aspx';", True)
                    End If
                End If

            Else
                If Not (strError = "") Then
                    ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                                  UpdatePanel1.GetType(), _
                                                                                  "clientScript", _
                                                                                  "alert('" + strError.Replace("'", "") + "')", _
                                                                                  True)
                ElseIf Not (strMsg = "") Then
                    ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                                 UpdatePanel1.GetType(), _
                                                                                 "clientScript", _
                                                                                 "alert('" + strMsg + "')", _
                                                                                 True)
                End If
            End If
        Else
            If Not (strError = "") Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                              UpdatePanel1.GetType(), _
                                                                              "clientScript", _
                                                                              "alert('" + strError.Replace("'", "") + "')", _
                                                                              True)
            ElseIf Not (strMsg = "") Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                             UpdatePanel1.GetType(), _
                                                                             "clientScript", _
                                                                             "alert('" + strMsg + "')", _
                                                                             True)
            End If
        End If
    End Sub

#End Region

#End Region

#Region " Function "
    Private Sub SaveLogPrint(ByVal index As Integer, ByVal strCode As String)
        Try
            Dim program As String = "M52"
            Dim desc As String = ""
            Dim strUnique As String = "033"
            Dim strFullNo As String = ""

            clsSessionMenuRight = Session("ClsMenuRight")

            If index = 3 Then 'add new
                desc = String.Format("{0} ", "บันทึก ข้อมูล ปปง.1-02")


            ElseIf index = 4 Then 'add edit
                desc = String.Format("{0} ", "บันทึก แก้ไข ปปง.1-02")
            End If

            'Dim strFullNo As String = CType(grdAmlo.Rows(grdAmlo.SelectedIndex).FindControl("hdfRptFullNo"), HiddenField).Value

            '033 deptcode branchcode year2 no 
            '033
            'clsSessionMenuRight.getDeptCode
            'ddlBranch.SelectedValue.Substring(0, 3)
            strFullNo = String.Format("033{0}{1}{2}{3}", clsSessionMenuRight.getDeptCode, ddlBranch.SelectedValue.Substring(0, 3), txtYear.Text.Trim, strCode)
            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(strFullNo.Trim, clsSessionMenuRight.getUserName, index, desc, program)
            'clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub SetClickTab(ByVal tabClick As enmTabClick)
        If (tabClick = enmTabClick.tab1) Then
            Panel1.Visible = True
            Panel5.Visible = True
            Panel2.Visible = False
            Panel3.Visible = False
            ibtnTab1.ImageUrl = "~/img/icon/button_1Select.jpg"
            ibtnTab2.ImageUrl = "~/img/icon/button_2UnSelect.jpg"
            ibtnTab3.ImageUrl = "~/img/icon/button_3UnSelect.jpg"
        ElseIf (tabClick = enmTabClick.tab2) Then
            Panel1.Visible = False
            Panel5.Visible = False
            Panel2.Visible = True
            Panel3.Visible = False
            ibtnTab1.ImageUrl = "~/img/icon/button_1UnSelect.jpg"
            ibtnTab2.ImageUrl = "~/img/icon/button_2Select.jpg"
            ibtnTab3.ImageUrl = "~/img/icon/button_3UnSelect.jpg"
        ElseIf (tabClick = enmTabClick.tab3) Then
            Panel1.Visible = False
            Panel5.Visible = True
            Panel2.Visible = False
            Panel3.Visible = True
            ibtnTab1.ImageUrl = "~/img/icon/button_1UnSelect.jpg"
            ibtnTab2.ImageUrl = "~/img/icon/button_2UnSelect.jpg"
            ibtnTab3.ImageUrl = "~/img/icon/button_3Select.jpg"
        End If
    End Sub

    Sub CreateControlMP() 'อ้าง control ใน masterPage เซ็ต กรอบว่าเป็น amlo ไหน
        Dim img As Image = CType(Master.FindControl("imgHead"), Image)
        img.ImageUrl = "~/img/amlo01_02.jpg"
        Dim lbl As Label = CType(Master.FindControl("lblPage"), Label)
        lbl.Text = "ข้อมูล ปปง.1-02"
    End Sub

    Private Sub setBranch() 'ตั้งค่าหน้าเว็บ
        Try
            BranchEntity = New userEntities
            Dim qryBranch = (From b In BranchEntity.SBRANCH
                               Select b.BRANCHCODE, b.BRANCHNAME).ToList

            ddlBranch.DataSource = qryBranch
            ddlBranch.DataTextField = "BRANCHNAME"
            ddlBranch.DataValueField = "BRANCHCODE"
            ddlBranch.DataBind()
            ddlBranch.Items.Insert(0, "** กรุณาเลือกสาขา **")

            qryBranch = Nothing
            BranchEntity.Dispose()
            BranchEntity = Nothing
        Catch ex As Exception

            Throw ex

        End Try
    End Sub


    Private Sub LoadDataToDropdown()
      
        clsMasterDropDown.setBranchToDdl_AMLO102(ddlBranch, AMLOEntity)
        clsMasterDropDown.setPSNRelationToDdl_AMLO102(ddlIdxType, AMLOEntity)
        clsMasterDropDown.setIDTypeToDdl_AMLO102Part1(ddlUniqueType, AMLOEntity)
        clsMasterDropDown.setIDTypeToDdl_AMLO102Part2(ddlUniqueType0, AMLOEntity)
        clsMasterDropDown.setOfficeOCCToDdl_AMLO102(ddlJob, AMLOEntity)
        clsMasterDropDown.setOfficeOCCToDdl_AMLO102(ddlJob0, AMLOEntity)
        clsMasterDropDown.setOFFICETYPEToDdl_AMLO102(ddlBizType, AMLOEntity)
        clsMasterDropDown.setTypeIDToDdl_AMLO102(ddlTranEV, AMLOEntity)
        clsMasterDropDown.setTypeIDToDdl_AMLO102(ddlTranEV0, AMLOEntity)
        clsMasterDropDown.setTSCTypeToDdl_AMLO102(ddlTransType, AMLOEntity)
        clsMasterDropDown.setAssetTypeToDdl_AMLO102(ddlAsset, AMLOEntity)
        clsMasterDropDown.setRefTypeToDdl_AMLO102(ddlRelation, AMLOEntity)
        clsMasterDropDown.setObjTypeToDdl_AMLO102(ddlObjName, AMLOEntity)
    End Sub

    Public Sub setDefaultEnable()
        'txtBankCode.Enabled = False
        txtRev.Enabled = False
        txtDate.Enabled = False
        ddlBranch.Enabled = False
        txtYear.Enabled = False
        ' txtTransDate.Enabled = False
        txtNo.Enabled = False
        txtSaveDate.Enabled = False
    End Sub

    Public Sub setDefaultValue()
        clsFormatDate = New clsDateFormat
        clsSessionMenuRight = Session("ClsMenuRight")
        Try
            ddlBranch.SelectedValue = clsSessionMenuRight.getBranchCode
            'txtYear.Text = clsFormatDate.GetYearLast(clsDateFormat.enmDateCultureInfo.Th).Substring(2, 2)
            ' txtBankCode.Text = ""
            txtRev.Text = 0
            txtDate.Text = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, dteDateIsChk:=Date.Now)
            'rdolIdxType.SelectedValue = 1
            txtTransDate.Text = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, dteDateIsChk:=Date.Now)

            Dim strDate As String = Nothing
            strDate = txtTransDate.Text.Split("/")(2)
            txtYear.Text = strDate.Substring(2, 2)

            'txtBankCode.Text = "033"
            txtNo.Text = "Auto Gen Code"
            txtSaveDate.Text = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, dteDateIsChk:=Date.Now)
            txtCurrency.Text = "บาท"
            rdoSaveType.SelectedValue = 0
            rdoSignType.SelectedValue = 1
            rdolIsComple.SelectedValue = 1
        Catch ex As Exception
            Throw ex
        End Try
        clsFormatDate = Nothing
    End Sub

    Private Function ChkData() As Boolean
        Dim statusPass As Boolean = True
        Dim clsCheckID As New clsCheckID
        If (rdolIsComple.SelectedValue = 0) Then
            Return statusPass
        End If

        strMsg = ""

        Try
            '----------------------------------part 1--------------------------------------------------
         
            If Not (hdfUniqueID_Part1.Value = txtUniqueID.Text.Trim) Then
                If Not (chkCardIdDuplicatePart1(txtUniqueID.Text.Trim)) Then
                    statusPass = False
                    strMsg = strMsg + "ส่วนที่ 1 เลขที่ " + txtUniqueID.Text + " ได้มีการกรอกข้อมูลไปแล้วในส่วนที่ 2 " + "\n"
                End If
            End If

            If Not (ddlUniqueType.SelectedIndex = 0) Then
                If (ddlUniqueType.SelectedValue = 1) Then 'บัตรประชาชน มีความยาว 13 หลัก

                    If Not (clsCheckID.chkIDcard(txtUniqueID.Text.Trim)) Then
                        statusPass = False
                        strMsg = strMsg + "ส่วนที่ 1 เลขที่ " + " " + String.Format(clsCheckID.Msg) + "\n"
                    End If

                End If


                If (ddlUniqueType.SelectedValue = 3) Then 'บัตรหนังสือเดินทาง มีความยาว 6-10 หลัก
                    If Not (txtUniqueID.Text.Trim.Length > 5 And txtUniqueID.Text.Trim.Length < 11) Then
                        statusPass = False
                        strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Length, Resources.resValidateAmlo.Part1, "เลขที่ (ชนิด)") + "\n"
                    End If
                End If
               
                If (ddlUniqueType.SelectedValue = 9) Then 'อื่นๆ มีความยาวไม่เกิน 15 หลัก
                    If Not (txtUniqueID.Text.Trim.Length < 16) Then
                        statusPass = False
                        strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Length, Resources.resValidateAmlo.Part1, "เลขที่ (ชนิด)") + "\n"
                    End If
                End If
            Else
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.Part1, "เลขที่ (ชนิด)") + "\n"
            End If

            If (txtPrefix.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "คำนำหน้า") + "\n"
            End If

            If (txtFirstName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "ชื่อ") + "\n"
            End If

            If (txtMidName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "ชื่อกลาง") + "\n"
            End If

            If (txtLastName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "นามสกุล") + "\n"
            End If

            If (txtFormalAddr.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "ที่อยู่") + "\n"
            End If
            If (txtFormalPhone.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "โทรศัพท์") + "\n"
            End If
            If (txtFormalFax.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "โทรสาร") + "\n"
            End If

            If (ddlJob.SelectedIndex = 0) Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.Part1, "อาชีพ") + "\n"
            End If
            If (txtWorkOther.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "ข้อมูลอาชีพ") + "\n"
            End If
            If (txtWorkAddr.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "สถานที่ทำงาน") + "\n"
            End If
            If (txtWorkPhone.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "โทรศัพท์ที่ทำงาน") + "\n"
            End If
            If (txtWorkFax.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "โทรสารที่ทำงาน") + "\n"
            End If


            If (txtContactAddr.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "สถานที่ติดต่อ") + "\n"
            End If
            If (txtContactPhone.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "โทรศัพท์ที่ติดต่อ") + "\n"
            End If
            If (txtContactFax.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "โทรสารที่ติดต่อ") + "\n"
            End If

            If (ddlTranEV.SelectedIndex = 0) Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.Part1, "หลักฐานทำธุรกรรม") + "\n"
            Else
                If (ddlTranEV.SelectedValue = 1) Then 'บัตรประชาชน มีความยาว 13 หลัก
                    If Not (txtEVNo.Text.Trim.Length = 13) Then
                        statusPass = False
                        strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Length, Resources.resValidateAmlo.Part1, "เลขที่ (หลักฐานทำธุรกรรม)") + "\n"
                    Else
                        If Not (chkIDcard(txtEVNo.Text)) Then
                            statusPass = False
                            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_IDCard, Resources.resValidateAmlo.Part1, txtEVNo.Text) + "\n"
                        End If
                    End If
                End If

                If (ddlTranEV.SelectedValue = 3) Then 'บัตรหนังสือเดินทาง มีความยาว 6-10 หลัก
                    If Not (txtEVNo.Text.Trim.Length > 5 And txtEVNo.Text.Trim.Length < 11) Then
                        statusPass = False
                        strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Length, Resources.resValidateAmlo.Part1, "เลขที่ (หลักฐานทำธุรกรรม)") + "\n"
                    End If
                End If

                If (ddlTranEV.SelectedValue = 7) Then
                    If (txtTranEVOther.Text.Trim = "") Then
                        statusPass = False
                        strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "ข้อมูลเพิ่มเติม (หลักฐานทำธุรกรรม)") + "\n"
                    End If
                End If
            End If

            If (txtTranEVOther.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "ข้อมูลเพิ่มเติม") + "\n"
            End If

            If (txtEVNo.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "เลขที่หลักฐาน") + "\n"
            End If

            If (txtEVBy.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "ออกโดย") + "\n"
            End If

            If (txtEvGen.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "ออกเมื่อ") + "\n"
            Else
                '------------------------------------------------เช็ควันที่----------------------------------------------------------
                If Not (clsFormatDate.ChkConvertIntToDate(clsDateFormat.enmDateCultureInfo.Th, txtEvGen.Text)) Then
                    If Not (clsFormatDate.chkFormatString(txtEvGen.Text.Trim) And txtEvGen.Text.Trim = "-") Then
                        statusPass = False
                        strMsg = strMsg + String.Format(Resources.resValidateAmlo.validate_Date, Resources.resValidateAmlo.Part1, "ออกเมื่อ") + "\n"
                    End If
                End If
                '----------------------------------------------------------------------------------------------------------------
            End If


            If (txtEvExpire.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.Part1, "วันหมดอายุ") + "\n"
            Else
                '------------------------------------------------เช็ควันที่----------------------------------------------------------
                If Not (clsFormatDate.ChkConvertIntToDate(clsDateFormat.enmDateCultureInfo.Th, txtEvExpire.Text)) Then
                    If Not (clsFormatDate.chkFormatString(txtEvExpire.Text.Trim) And txtEvExpire.Text.Trim = "-") Then
                        statusPass = False
                        strMsg = strMsg + String.Format(Resources.resValidateAmlo.validate_Date, Resources.resValidateAmlo.Part1, "วันหมดอายุ") + "\n"
                    End If
                End If
                '----------------------------------------------------------------------------------------------------------------

            End If

            If (ddlUniqueType.SelectedValue = ddlTranEV.SelectedValue) Then
                If Not (txtEVNo.Text = txtUniqueID.Text) Then
                    statusPass = False
                    strMsg = strMsg + "ส่วนที่ 1 เลขที่ ของชนิดบัตรไม่ตรงกันกับ เลขที่หลักฐานทำธุรกรรม " + "\n"
                End If
            End If

            '------------------------------------------------End part 1-----------------------------------------------------




            '------------------------------------------------part 3---------------------------------------------------------
            If (txtTransDate.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "วันที่ทำธุรกรรม") + "\n"
            Else
                '------------------------------------------------เช็ควันที่----------------------------------------------------------
                If Not (clsFormatDate.ChkConvertIntToDate(clsDateFormat.enmDateCultureInfo.Th, txtTransDate.Text)) Then
                    If Not (clsFormatDate.chkFormatString(txtTransDate.Text.Trim)) Then
                        statusPass = False
                        strMsg = strMsg + String.Format(Resources.resValidateAmlo.validate_Date, Resources.resValidateAmlo.part3, "วันที่ทำธุรกรรม") + "\n"
                    End If
                End If
                '----------------------------------------------------------------------------------------------------------------

            End If


            If (ddlTransType.SelectedIndex = 0) Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.part3, "ชนิดของธุรกรรม") + "\n"
            End If


            If (txtTransTypeOther.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ข้อมูลเพิ่มเติม (ชนิดของธุรกรรม)") + "\n"
            End If

            If (ddlAsset.SelectedIndex = 0) Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.part3, "ประเภททรัพย์สิน") + "\n"
            End If

            If (txtAssetOther.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ข้อมูลเพิ่มเติม (ประเภททรัพย์สิน)") + "\n"
            End If

            If (txtAssetDetail.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "รายละเอียดของทรัพย์สิน") + "\n"
            End If


            If Not (chkDataTransAmt(txtTranAmt.Text.Trim)) Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "จำนวนเงิน") + "\n"
            Else
                If Not (chkDataTransAmtMore(txtTranAmt.Text.Trim)) Then
                    statusPass = False
                    strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Amount, Resources.resValidateAmlo.part3, "จำนวนเงิน") + "\n"
                End If
            End If
            If (txtCurrency.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "สกุลเงิน") + "\n"
            End If
            '---
            If (txtAccountNo.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "เลขที่บัญชีที่ทำธุรกรรม") + "\n"
            End If
            If (txtAccountName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ชื่อบัญชี (เลขที่บัญชีที่ทำธุรกรรม)") + "\n"
            End If

            If (txtAccountOwnerPrefix.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "คำนำหน้า") + "\n"
            End If
            If (txtAccountOwnerfirstName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ชื่อ") + "\n"
            End If
            If (txtAccountOwnerMidName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ชื่อกลาง") + "\n"
            End If
            If (txtAccountOwnerLastName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "นามสกุล") + "\n"
            End If
            '-----
            '---
            If (txtAccountNoRef.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "เลขที่บัญชีที่เกี่ยวข้อง") + "\n"
            End If
            If (txtAccountNameRef.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ชื่อบัญชี (เลขที่บัญชีที่เกี่ยวข้อง)") + "\n"
            End If

            If (txtAccountRefPrefix.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "คำนำหน้า") + "\n"
            End If
            If (txtAccountRefFirstName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ชื่อ") + "\n"
            End If
            If (txtAccountRefMidName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ชื่อกลาง") + "\n"
            End If
            If (txtAccountRefLastName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "นามสกุล") + "\n"
            End If
            '-----


            If (ddlRelation.SelectedIndex = 0) Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.part3, "เกี่ยวข้องโดย") + "\n"
            End If
            If (txtRelationOther.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ข้อมูลเพิ่มเติม (เกี่ยวข้องโดย)") + "\n"
            End If
            If (txtGainPrefix.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "คำนำหน้า (ผู้รับผลประโยชน์)") + "\n"
            End If

            If (txtGainFirstName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ชื่อ (ผู้รับผลประโยชน์)") + "\n"
            End If
            If (txtGainMidName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ชื่อกลาง (ผู้รับผลประโยชน์)") + "\n"
            End If
            If (txtGainLastName.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "นามสกุล (ผู้รับผลประโยชน์)") + "\n"
            End If

            If (ddlObjName.SelectedIndex = 0) Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.part3, "วัตถุประสงค์") + "\n"
            End If
            If (txtObjOther.Text.Trim = "") Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part3, "ข้อมูลเพิ่มเติม (วัตถุประสงค์)") + "\n"
            End If

            If Not difDate(txtSaveDate.Text, txtTransDate.Text) <= 0 Then
                statusPass = False
                strMsg = strMsg + String.Format(Resources.resValidateAmlo.validate_Different, Resources.resValidateAmlo.part3) + "\n"

            End If

            '------------------------------------------------End part 3-----------------------------------------------------


        Catch ex As Exception
            statusPass = False
            strError = ex.Message
        End Try
        clsCheckID = Nothing
        Return statusPass
    End Function

    Private Function difDate(ByVal beginDate As Date, ByVal endDate As Date) As Integer
        ' Dim blnChkDate As Boolean = False
        Dim dateDif As Integer
        Try
            dateDif = DateDiff(DateInterval.Day, beginDate, endDate)
        Catch ex As Exception
            Throw ex
        End Try

        Return dateDif
    End Function

    Private Function ChkDataPart2() As Boolean
        Dim statusPass As Boolean = True
        Dim clsCheckID As New clsCheckID

        clsFormatDate = New clsDateFormat
        strMsg = ""
        If (ddlIdxType.SelectedIndex = 0) Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.part2, "ผู้ทำธุรกรรม") + "\n"
        End If

        If Not (hdfUniqueID_Part2.Value = txtUniqueID0.Text.Trim) Then
            If Not (chkCardIdDuplicate(txtUniqueID0.Text.Trim)) Then
                statusPass = False
                strMsg = strMsg + "ส่วนที่ 2 เลขที่ " + txtUniqueID0.Text + " ได้มีการกรอกข้อมูลไปแล้วในส่วนที่ 1 " + "\n"
            End If
        End If

        If Not (ddlUniqueType0.SelectedIndex = 0) Then
            If (ddlUniqueType0.SelectedValue = 1) Then 'บัตรประชาชน มีความยาว 13 หลัก

                If Not (clsCheckID.chkIDcard(txtUniqueID0.Text.Trim)) Then
                    statusPass = False
                    strMsg = strMsg + "ส่วนที่ 2 เลขที่ " + " " + String.Format(clsCheckID.Msg) + "\n"
                End If
            End If

            If (ddlUniqueType0.SelectedValue = 3) Then 'บัตรหนังสือเดินทาง มีความยาว 6-10 หลัก
                If Not (txtUniqueID0.Text.Trim.Length > 5 And txtUniqueID0.Text.Trim.Length < 11) Then
                    statusPass = False
                    strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Length, Resources.resValidateAmlo.part2, "เลขที่ (ชนิด)") + "\n"
                End If
            End If

            If (ddlUniqueType0.SelectedValue = 9) Then 'อื่นๆ มีความยาวไม่เกิน 15 หลัก
                If Not (txtUniqueID0.Text.Trim.Length < 16) Then
                    statusPass = False
                    strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Length, Resources.resValidateAmlo.part2, "เลขที่ (ชนิด)") + "\n"
                End If
            End If
        Else
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.part2, "เลขที่ (ชนิด)") + "\n"
        End If

        If (txtUniqueID0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "เลขที่ (ชนิด)") + "\n"
        End If


        '-----------------------
        If (txtPrefix0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "คำนำหน้า") + "\n"
        End If


        If (txtFirstName0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ชื่อ") + "\n"
        End If

        If (txtMidName0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ชื่อกลาง") + "\n"
        End If

        If (txtLastName0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "นามสกุล") + "\n"
        End If

        If (txtFormalAddr0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ที่อยู่") + "\n"
        End If
        If (txtFormalPhone0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "โทรศัพท์") + "\n"
        End If
        If (txtFormalFax0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "โทรสาร") + "\n"
        End If

        If (ddlJob0.SelectedIndex = 0) Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "อาชีพ") + "\n"
        End If
        If (txtWorkOther0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ข้อมูลอาชีพ") + "\n"
        End If

        If (txtWorkAddr0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "สถานที่ทำงาน") + "\n"
        End If
        If (txtWorkPhone0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "โทรศัพท์ที่ทำงาน") + "\n"
        End If
        If (txtWorkFax0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "โทรสารที่ทำงาน") + "\n"
        End If
        If (ddlBizType.SelectedIndex = 0) Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ประเภทประกอบการ") + "\n"
        End If
        If (txtBizTypeOther.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ข้อมูลเพิ่มเติม(ประเภทประกอบการ)") + "\n"
        End If
        If (txtContactAddr0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "สถานที่ติดต่อ") + "\n"
        End If
        If (txtContactPhone0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "โทรศัพท์ที่ติดต่อ") + "\n"
        End If
        If (txtContactFax0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "โทรสารที่ติดต่อ") + "\n"
        End If

        '-----------------------



        If (ddlTranEV0.SelectedIndex = 0) Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Select, Resources.resValidateAmlo.part2, "หลักฐานทำธุรกรรม") + "\n"
        Else
            If (ddlTranEV0.SelectedValue = 1) Then 'บัตรประชาชน มีความยาว 13 หลัก
                If Not (txtEVNo0.Text.Trim.Length = 13) Then
                    statusPass = False
                    strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Length, Resources.resValidateAmlo.part2, "เลขที่ (หลักฐานทำธุรกรรม)") + "\n"
                Else
                    If Not (chkIDcard(txtEVNo0.Text)) Then
                        statusPass = False
                        strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_IDCard, Resources.resValidateAmlo.part2, txtEVNo0.Text) + "\n"
                    End If
                End If
            End If

            If (ddlTranEV0.SelectedValue = 3) Then 'บัตรหนังสือเดินทาง มีความยาว 6-10 หลัก
                If Not (txtEVNo0.Text.Trim.Length > 5 And txtEVNo0.Text.Trim.Length < 11) Then
                    statusPass = False
                    strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Length, Resources.resValidateAmlo.part2, "เลขที่ (หลักฐานทำธุรกรรม)") + "\n"
                End If
            End If

            If (ddlTranEV0.SelectedValue = 7) Then
                If (txtTranEVOther0.Text.Trim = "") Then
                    statusPass = False
                    strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ข้อมูลเพิ่มเติม (หลักฐานทำธุรกรรม)") + "\n"
                End If
            End If
        End If

        If (txtTranEVOther0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ข้อมูลเพิ่มเติม") + "\n"
        End If

        If (txtEVNo0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "เลขที่หลักฐาน") + "\n"
        End If

        If (txtEVBy0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ออกโดย") + "\n"
        End If


        If (txtEvGen0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "ออกเมื่อ") + "\n"
        Else
            '------------------------------------------------เช็ควันที่----------------------------------------------------------

            If Not (clsFormatDate.ChkConvertIntToDate(clsDateFormat.enmDateCultureInfo.Th, txtEvGen0.Text)) Then
                If Not (clsFormatDate.chkFormatString(txtEvGen0.Text.Trim) And txtEvGen0.Text.Trim = "-") Then
                    statusPass = False
                    strMsg = strMsg + String.Format(Resources.resValidateAmlo.validate_Date, Resources.resValidateAmlo.part2, "ออกเมื่อ") + "\n"
                End If
            End If
            '----------------------------------------------------------------------------------------------------------------
        End If

        If (txtEvExpire0.Text.Trim = "") Then
            statusPass = False
            strMsg = strMsg + String.Format(Resources.resValidateAmlo.valid_Text, Resources.resValidateAmlo.part2, "วันหมดอายุ") + "\n"
        Else
            '------------------------------------------------เช็ควันที่----------------------------------------------------------
            If Not (clsFormatDate.ChkConvertIntToDate(clsDateFormat.enmDateCultureInfo.Th, txtEvExpire0.Text)) Then
                If Not (clsFormatDate.chkFormatString(txtEvExpire0.Text.Trim) And txtEvExpire0.Text.Trim = "-") Then
                    statusPass = False
                    strMsg = strMsg + String.Format(Resources.resValidateAmlo.validate_Date, Resources.resValidateAmlo.part2, "วันหมดอายุ") + "\n"
                End If
            End If
            '----------------------------------------------------------------------------------------------------------------
        End If

        If (ddlUniqueType0.SelectedValue = ddlTranEV0.SelectedValue) Then
            If Not (txtEVNo0.Text = txtUniqueID0.Text) Then
                statusPass = False
                strMsg = strMsg + "ส่วนที่ 2 เลขที่ ของชนิดบัตรไม่ตรงกันกับ เลขที่หลักฐานทำธุรกรรม " + "\n"
            End If
        End If

        clsFormatDate = Nothing
        clsCheckID = Nothing
        Return statusPass
    End Function

    Private Function chkCardIdDuplicate(ByVal strUniqueID As String) As Boolean
        Dim blnDup As Boolean = True

        Dim qryDup = (From tblDup In dsAMLO.Tables("AmloDetail") Where tblDup.Item("uniqueid") = strUniqueID).ToList

        If Not (qryDup.Count = 0) Then
            blnDup = False
        End If

        If (strUniqueID.Trim = txtUniqueID.Text.Trim) Then
            blnDup = False
        End If

        qryDup = Nothing

        Return blnDup
    End Function

    Private Function chkCardIdDuplicatePart1(ByVal strUniqueID As String) As Boolean
        Dim blnDup As Boolean = True

        Dim qryDup = (From tblDup In dsAMLO.Tables("AmloDetail") Where tblDup.Item("uniqueid") = strUniqueID).ToList

        If Not (qryDup.Count = 0) Then
            blnDup = False
        End If

        'If (strUniqueID.Trim = txtUniqueID.Text.Trim) Then
        '    blnDup = False
        'End If

        qryDup = Nothing

        Return blnDup
    End Function

    Private Sub createStructure(Optional ByVal intRptSeq As Integer = 0) 'เป็นการสร้าง dataset เปล่าๆขึ้นมาเพื่อทำการเก็บข้อมูลรอการ save
        clsQry = New clsDatabase

        Try
            If dsAMLO.Tables.Contains("AmloDetail") Then
                dsAMLO.Tables("AmloDetail").Clear()
            Else
            End If
            Dim sql As String = "SELECT rptseq, rptidx, rptidxtype, " _
                                          & " uniquetype, uniqueid, prefix, " _
                                          & " FIRSTNAME, MIDNAME, LASTNAME, " _
                                          & " FORMALADDR, FORMALPHONE, FORMALFAX, " _
                                          & " OCCUPATIONTYPE, OCCUPATIONTYPEOTHER, " _
                                          & " WORKADDR, WORKPHONE, WORKFAX, " _
                                          & " BIZTYPE, BIZTYPEOTHER, CONTACTADDR, " _
                                          & " CONTACTPHONE, CONTACTFAX, CUSTIDTYPE, " _
                                          & " CUSTIDTYPEOTHER, CUSTID, EVBY, " _
                                          & " EVGEN,EVGENTEXT, EVEXPIRE,EVEXPIRETEXT, CREATEBY, " _
                                          & " CREATEDATE, UPDATEBY, UPDATEDATE " _
                                      & " FROM AmloDetail102 where RPTSEQ =  " & intRptSeq

            dsAMLO.Tables.Add(clsQry.QueryDataSet(sql, "AmloDetail").Tables("AmloDetail").Copy)

        Catch ex As Exception
            Throw ex
        End Try

        clsQry = Nothing
    End Sub

    Private Sub SetDataCustomerpart1(ByVal SelectPart As enmPartSearch, Optional ByVal dtCusAmlo As DataTable = Nothing, _
                                 Optional ByVal tblmCus As DataTable = Nothing)
        clsFormatDate = New clsDateFormat
        Try
            If Not (tblmCus Is Nothing) Then 'ดึงมาจาก ถัง KYC
                If (SelectPart = enmPartSearch.part1) Then
                    txtPrefix.Text = If(tblmCus.Rows(0)("THPREFIX") Is DBNull.Value, "", tblmCus.Rows(0)("THPREFIX"))
                    txtFirstName.Text = If(tblmCus.Rows(0)("THFIRSTNAME") Is DBNull.Value, "", tblmCus.Rows(0)("THFIRSTNAME"))
                    txtMidName.Text = If(tblmCus.Rows(0)("THMIDNAME") Is DBNull.Value, "", tblmCus.Rows(0)("THMIDNAME"))
                    txtLastName.Text = If(tblmCus.Rows(0)("THLASTNAME") Is DBNull.Value, "", tblmCus.Rows(0)("THLASTNAME"))
                    txtFormalAddr.Text = If(tblmCus.Rows(0)("FORMALADDR") Is DBNull.Value, "", tblmCus.Rows(0)("FORMALADDR"))
                    txtFormalPhone.Text = If(tblmCus.Rows(0)("FORMALPHONE1") Is DBNull.Value, "", tblmCus.Rows(0)("FORMALPHONE1"))
                    txtFormalFax.Text = If(tblmCus.Rows(0)("FORMALFAX") Is DBNull.Value, "", tblmCus.Rows(0)("FORMALFAX"))
                    'txtWorkOther.Text = tblmCus(0).OCCUPATIONTYPEOTHER1
                    txtWorkAddr.Text = If(tblmCus.Rows(0)("WORKADDR") Is DBNull.Value, "", tblmCus.Rows(0)("WORKADDR"))
                    txtWorkPhone.Text = If(tblmCus.Rows(0)("WORKPHONE1") Is DBNull.Value, "", tblmCus.Rows(0)("WORKPHONE1"))
                    txtWorkFax.Text = If(tblmCus.Rows(0)("WORKFAX") Is DBNull.Value, "", tblmCus.Rows(0)("WORKFAX"))
                    txtContactAddr.Text = If(tblmCus.Rows(0)("CONTACTADDR") Is DBNull.Value, "", tblmCus.Rows(0)("CONTACTADDR"))
                    txtContactPhone.Text = If(tblmCus.Rows(0)("CONTACTPHONE1") Is DBNull.Value, "", tblmCus.Rows(0)("CONTACTPHONE1"))
                    txtContactFax.Text = If(tblmCus.Rows(0)("CONTACTFAX") Is DBNull.Value, "", tblmCus.Rows(0)("CONTACTFAX"))




                ElseIf (SelectPart = enmPartSearch.part2) Then
                    txtPrefix0.Text = If(tblmCus.Rows(0)("THPREFIX") Is DBNull.Value, "", tblmCus.Rows(0)("THPREFIX"))
                    txtFirstName0.Text = If(tblmCus.Rows(0)("THFIRSTNAME") Is DBNull.Value, "", tblmCus.Rows(0)("THFIRSTNAME"))
                    txtMidName0.Text = If(tblmCus.Rows(0)("THMIDNAME") Is DBNull.Value, "", tblmCus.Rows(0)("THMIDNAME"))
                    txtLastName0.Text = If(tblmCus.Rows(0)("THLASTNAME") Is DBNull.Value, "", tblmCus.Rows(0)("THLASTNAME"))
                    txtFormalAddr0.Text = If(tblmCus.Rows(0)("FORMALADDR") Is DBNull.Value, "", tblmCus.Rows(0)("FORMALADDR"))
                    txtFormalPhone0.Text = If(tblmCus.Rows(0)("FORMALPHONE1") Is DBNull.Value, "", tblmCus.Rows(0)("FORMALPHONE1"))
                    txtFormalFax0.Text = If(tblmCus.Rows(0)("FORMALFAX") Is DBNull.Value, "", tblmCus.Rows(0)("FORMALFAX"))
                    'txtWorkOther.Text = tblmCus(0).OCCUPATIONTYPEOTHER1
                    txtWorkAddr0.Text = If(tblmCus.Rows(0)("WORKADDR") Is DBNull.Value, "", tblmCus.Rows(0)("WORKADDR"))
                    txtWorkPhone0.Text = If(tblmCus.Rows(0)("WORKPHONE1") Is DBNull.Value, "", tblmCus.Rows(0)("WORKPHONE1"))
                    txtWorkFax0.Text = If(tblmCus.Rows(0)("WORKFAX") Is DBNull.Value, "", tblmCus.Rows(0)("WORKFAX"))
                    txtContactAddr0.Text = If(tblmCus.Rows(0)("CONTACTADDR") Is DBNull.Value, "", tblmCus.Rows(0)("CONTACTADDR"))
                    txtContactPhone0.Text = If(tblmCus.Rows(0)("CONTACTPHONE1") Is DBNull.Value, "", tblmCus.Rows(0)("CONTACTPHONE1"))
                    txtContactFax0.Text = If(tblmCus.Rows(0)("CONTACTFAX") Is DBNull.Value, "", tblmCus.Rows(0)("CONTACTFAX"))
                End If

            ElseIf Not (dtCusAmlo Is Nothing) Then 'ดึงมาจาก ถัง amlo

                If (SelectPart = enmPartSearch.part1) Then
                    txtPrefix.Text = If(dtCusAmlo.Rows(0)("PREFIX") Is DBNull.Value, "", dtCusAmlo.Rows(0)("PREFIX"))
                    txtFirstName.Text = If(dtCusAmlo.Rows(0)("FIRSTNAME") Is DBNull.Value, "", dtCusAmlo.Rows(0)("FIRSTNAME"))
                    txtMidName.Text = If(dtCusAmlo.Rows(0)("MIDNAME") Is DBNull.Value, "", dtCusAmlo.Rows(0)("MIDNAME"))
                    txtLastName.Text = If(dtCusAmlo.Rows(0)("LASTNAME") Is DBNull.Value, "", dtCusAmlo.Rows(0)("LASTNAME"))
                    txtFormalAddr.Text = If(dtCusAmlo.Rows(0)("FORMALADDR") Is DBNull.Value, "", dtCusAmlo.Rows(0)("FORMALADDR"))
                    txtFormalPhone.Text = If(dtCusAmlo.Rows(0)("FORMALPHONE") Is DBNull.Value, "", dtCusAmlo.Rows(0)("FORMALPHONE"))
                    txtFormalFax.Text = If(dtCusAmlo.Rows(0)("FORMALFAX") Is DBNull.Value, "", dtCusAmlo.Rows(0)("FORMALFAX"))

                    If (dtCusAmlo.Rows(0)("OCCUPATIONTYPE") Is DBNull.Value) Then
                        ddlJob.SelectedValue = "0"
                    Else
                        ddlJob.SelectedValue = dtCusAmlo.Rows(0)("OCCUPATIONTYPE")
                    End If
                    txtWorkOther.Text = If(dtCusAmlo.Rows(0)("OCCUPATIONTYPEOTHER") Is DBNull.Value, "", dtCusAmlo.Rows(0)("OCCUPATIONTYPEOTHER"))

                    txtWorkAddr.Text = If(dtCusAmlo.Rows(0)("WORKADDR") Is DBNull.Value, "", dtCusAmlo.Rows(0)("WORKADDR"))
                    txtWorkPhone.Text = If(dtCusAmlo.Rows(0)("WORKPHONE") Is DBNull.Value, "", dtCusAmlo.Rows(0)("WORKPHONE"))
                    txtWorkFax.Text = If(dtCusAmlo.Rows(0)("WORKFAX") Is DBNull.Value, "", dtCusAmlo.Rows(0)("WORKFAX"))
                    txtContactAddr.Text = If(dtCusAmlo.Rows(0)("CONTACTADDR") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CONTACTADDR"))
                    txtContactPhone.Text = If(dtCusAmlo.Rows(0)("CONTACTPHONE") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CONTACTPHONE"))
                    txtContactFax.Text = If(dtCusAmlo.Rows(0)("CONTACTFAX") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CONTACTFAX"))

                    If (dtCusAmlo.Rows(0)("CUSTIDTYPE") Is DBNull.Value) Then
                        ddlTranEV.SelectedValue = "0"
                    Else

                        ddlTranEV.SelectedValue = dtCusAmlo.Rows(0)("CUSTIDTYPE")
                    End If
                    txtTranEVOther.Text = If(dtCusAmlo.Rows(0)("CUSTIDTYPEOTHER") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CUSTIDTYPEOTHER"))

                    txtEVNo.Text = If(dtCusAmlo.Rows(0)("CUSTID") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CUSTID"))
                    txtEVBy.Text = If(dtCusAmlo.Rows(0)("EVBY") Is DBNull.Value, "", dtCusAmlo.Rows(0)("EVBY"))
                    txtEvGen.Text = If(dtCusAmlo.Rows(0)("EVGENTEXT") Is DBNull.Value, "", dtCusAmlo.Rows(0)("EVGENTEXT"))
                    txtEvExpire.Text = If(dtCusAmlo.Rows(0)("EVEXPIRETEXT") Is DBNull.Value, "", dtCusAmlo.Rows(0)("EVEXPIRETEXT"))

                ElseIf (SelectPart = enmPartSearch.part2) Then

                    txtPrefix0.Text = If(dtCusAmlo.Rows(0)("PREFIX") Is DBNull.Value, "", dtCusAmlo.Rows(0)("PREFIX"))
                    txtFirstName0.Text = If(dtCusAmlo.Rows(0)("FIRSTNAME") Is DBNull.Value, "", dtCusAmlo.Rows(0)("FIRSTNAME"))
                    txtMidName0.Text = If(dtCusAmlo.Rows(0)("MIDNAME") Is DBNull.Value, "", dtCusAmlo.Rows(0)("MIDNAME"))
                    txtLastName0.Text = If(dtCusAmlo.Rows(0)("LASTNAME") Is DBNull.Value, "", dtCusAmlo.Rows(0)("LASTNAME"))
                    txtFormalAddr0.Text = If(dtCusAmlo.Rows(0)("FORMALADDR") Is DBNull.Value, "", dtCusAmlo.Rows(0)("FORMALADDR"))
                    txtFormalPhone0.Text = If(dtCusAmlo.Rows(0)("FORMALPHONE") Is DBNull.Value, "", dtCusAmlo.Rows(0)("FORMALPHONE"))
                    txtFormalFax0.Text = If(dtCusAmlo.Rows(0)("FORMALFAX") Is DBNull.Value, "", dtCusAmlo.Rows(0)("FORMALFAX"))

                    If (dtCusAmlo.Rows(0)("OCCUPATIONTYPE") Is DBNull.Value) Then
                        ddlJob0.SelectedValue = "0"
                    Else
                        ddlJob0.SelectedValue = dtCusAmlo.Rows(0)("OCCUPATIONTYPE")
                    End If
                    txtWorkOther0.Text = If(dtCusAmlo.Rows(0)("OCCUPATIONTYPEOTHER") Is DBNull.Value, "", dtCusAmlo.Rows(0)("OCCUPATIONTYPEOTHER"))

                    txtWorkAddr0.Text = If(dtCusAmlo.Rows(0)("WORKADDR") Is DBNull.Value, "", dtCusAmlo.Rows(0)("WORKADDR"))
                    txtWorkPhone0.Text = If(dtCusAmlo.Rows(0)("WORKPHONE") Is DBNull.Value, "", dtCusAmlo.Rows(0)("WORKPHONE"))
                    txtWorkFax0.Text = If(dtCusAmlo.Rows(0)("WORKFAX") Is DBNull.Value, "", dtCusAmlo.Rows(0)("WORKFAX"))

                    If (dtCusAmlo.Rows(0)("BIZTYPE") Is DBNull.Value) Then
                        ddlBizType.SelectedValue = "0"
                    Else
                        ddlBizType.SelectedValue = dtCusAmlo.Rows(0)("BIZTYPE")
                    End If
                    txtBizTypeOther.Text = If(dtCusAmlo.Rows(0)("BIZTYPEOTHER") Is DBNull.Value, "", dtCusAmlo.Rows(0)("BIZTYPEOTHER"))

                    txtContactAddr0.Text = If(dtCusAmlo.Rows(0)("CONTACTADDR") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CONTACTADDR"))
                    txtContactPhone0.Text = If(dtCusAmlo.Rows(0)("CONTACTPHONE") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CONTACTPHONE"))
                    txtContactFax0.Text = If(dtCusAmlo.Rows(0)("CONTACTFAX") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CONTACTFAX"))

                    If (dtCusAmlo.Rows(0)("CUSTIDTYPE") Is DBNull.Value) Then
                        ddlTranEV0.SelectedValue = "0"
                    Else

                        ddlTranEV0.SelectedValue = dtCusAmlo.Rows(0)("CUSTIDTYPE")
                    End If
                    txtTranEVOther0.Text = If(dtCusAmlo.Rows(0)("CUSTIDTYPEOTHER") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CUSTIDTYPEOTHER"))

                    txtEVNo0.Text = If(dtCusAmlo.Rows(0)("CUSTID") Is DBNull.Value, "", dtCusAmlo.Rows(0)("CUSTID"))
                    txtEVBy0.Text = If(dtCusAmlo.Rows(0)("EVBY") Is DBNull.Value, "", dtCusAmlo.Rows(0)("EVBY"))
                    txtEvGen0.Text = If(dtCusAmlo.Rows(0)("EVGENTEXT") Is DBNull.Value, "", dtCusAmlo.Rows(0)("EVGENTEXT"))
                    txtEvExpire0.Text = If(dtCusAmlo.Rows(0)("EVEXPIRETEXT") Is DBNull.Value, "", dtCusAmlo.Rows(0)("EVEXPIRETEXT"))


                End If

            End If
        Catch ex As Exception
            Throw ex
        End Try
        clsFormatDate = Nothing
    End Sub

    Public Sub SetDataCustomerpart2(Optional ByVal tblmCus As IList(Of MCUSTOMER) = Nothing, _
                              Optional ByVal tblAmloDetail As IList(Of AMLODETAIL102) = Nothing)
        clsFormatDate = New clsDateFormat
        Try
            If Not (tblmCus Is Nothing) Then
                txtPrefix0.Text = tblmCus(0).THPREFIX
                txtFirstName0.Text = tblmCus(0).THFIRSTNAME
                txtMidName0.Text = tblmCus(0).THMIDNAME
                txtLastName0.Text = tblmCus(0).THLASTNAME
                txtFormalAddr0.Text = tblmCus(0).FORMALADDR
                txtFormalPhone0.Text = tblmCus(0).FORMALPHONE1
                txtFormalFax0.Text = tblmCus(0).FORMALFAX
                txtWorkOther0.Text = tblmCus(0).OCCUPATIONTYPEOTHER1
                txtWorkAddr0.Text = tblmCus(0).WORKADDR
                txtWorkPhone0.Text = tblmCus(0).WORKPHONE1
                txtWorkFax0.Text = tblmCus(0).WORKFAX
                txtContactAddr0.Text = tblmCus(0).CONTACTADDR
                txtContactPhone0.Text = tblmCus(0).CONTACTPHONE1
                txtContactFax0.Text = tblmCus(0).CONTACTFAX
            ElseIf Not (tblAmloDetail Is Nothing) Then
                txtPrefix0.Text = tblAmloDetail(0).PREFIX
                txtFirstName0.Text = tblAmloDetail(0).FIRSTNAME
                txtMidName0.Text = tblAmloDetail(0).MIDNAME
                txtLastName0.Text = tblAmloDetail(0).LASTNAME
                txtFormalAddr0.Text = tblAmloDetail(0).FORMALADDR
                txtFormalPhone0.Text = tblAmloDetail(0).FORMALPHONE
                txtFormalFax0.Text = tblAmloDetail(0).FORMALFAX
                txtWorkOther0.Text = tblAmloDetail(0).OCCUPATIONTYPEOTHER
                txtWorkAddr0.Text = tblAmloDetail(0).WORKADDR
                txtWorkPhone0.Text = tblAmloDetail(0).WORKPHONE
                txtWorkFax0.Text = tblAmloDetail(0).WORKFAX
                txtContactAddr0.Text = tblAmloDetail(0).CONTACTADDR
                txtContactPhone0.Text = tblAmloDetail(0).CONTACTPHONE
                txtContactFax0.Text = tblAmloDetail(0).CONTACTFAX
            End If
        Catch ex As Exception
            Throw ex
        End Try
        clsFormatDate = Nothing
    End Sub

    Private Sub loadData(ByVal strRptSeq As String)
        '  AMLOEntity = New AMLO101Entities
        Try
            Dim tbRpt = (From tblMaster In AMLOEntity.AMLO102 Where tblMaster.RPTSEQ = strRptSeq).ToList
            createStructure(tbRpt(0).RPTSEQ)
            setDataToPage(tbRpt)
            setTextLength(ddlUniqueType, txtUniqueID)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region

#Region " Add  Data To Page "

    Private Sub setDataToPage(ByVal tblAmlo As IList(Of AMLO102))
        clsFormatDate = New clsDateFormat
        Try


            ' ส่วนที่ 1 -----------------------------------------

            hdfRptSeq.Value = tblAmlo(0).RPTSEQ
            ddlBranch.SelectedValue = tblAmlo(0).BRANCHCODE
            txtYear.Text = tblAmlo(0).RPTYEAR
            If (tblAmlo(0).ISSEND = True) Then
                txtRev.Text = tblAmlo(0).RPTREV + 1
            Else
                txtRev.Text = tblAmlo(0).RPTREV
            End If

            txtNo.Text = tblAmlo(0).RPTNO
            txtDate.Text = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, tblAmlo(0).RPTDATE)
            '--------------------------------------------------

            ' ส่วนที่ 2 -----------------------------------------

            Dim drCusMaster() As DataRow = dsAMLO.Tables("AmloDetail").Select("RPTIDX = 1")

            ' rdolIdxType.SelectedValue = drCusMaster(0)("RPTIDXTYPE")
            Try
                If Not (drCusMaster(0)("UNIQUETYPE") Is Nothing Or drCusMaster(0)("UNIQUETYPE") Is DBNull.Value) Then
                    ddlUniqueType.SelectedValue = drCusMaster(0)("UNIQUETYPE")
                Else
                    ddlUniqueType.SelectedIndex = 0
                End If
            Catch ex As Exception

            End Try

            txtUniqueID.Text = IIf(drCusMaster(0)("UNIQUEID") Is DBNull.Value, "", drCusMaster(0)("UNIQUEID"))
            hdfUniqueID_Part1.Value = IIf(drCusMaster(0)("UNIQUEID") Is DBNull.Value, "", drCusMaster(0)("UNIQUEID"))

            txtPrefix.Text = IIf(drCusMaster(0)("PreFix") Is DBNull.Value, "", drCusMaster(0)("PreFix"))

            txtFirstName.Text = IIf(drCusMaster(0)("FirstName") Is DBNull.Value, "", drCusMaster(0)("FirstName"))
            txtMidName.Text = IIf(drCusMaster(0)("MidName") Is DBNull.Value, "", drCusMaster(0)("MidName"))
            txtLastName.Text = IIf(drCusMaster(0)("LastName") Is DBNull.Value, "", drCusMaster(0)("LastName"))
            txtFormalAddr.Text = IIf(drCusMaster(0)("FORMALADDR") Is DBNull.Value, "", drCusMaster(0)("FORMALADDR"))
            txtFormalPhone.Text = IIf(drCusMaster(0)("FORMALPHONE") Is DBNull.Value, "", drCusMaster(0)("FORMALPHONE"))
            txtFormalFax.Text = IIf(drCusMaster(0)("FORMALFAX") Is DBNull.Value, "", drCusMaster(0)("FORMALFAX"))
            Try
                If Not (drCusMaster(0)("OccupationType") Is Nothing Or drCusMaster(0)("OccupationType") Is DBNull.Value) Then
                    ddlJob.SelectedValue = drCusMaster(0)("OccupationType")
                Else
                    ddlJob.SelectedIndex = 0
                End If
            Catch ex As Exception

            End Try

            txtWorkOther.Text = IIf(drCusMaster(0)("OccupationTypeOther") Is DBNull.Value, "", drCusMaster(0)("OccupationTypeOther")) 'อาชีพอื่นๆ
            txtWorkAddr.Text = IIf(drCusMaster(0)("WORKADDR") Is DBNull.Value, "", drCusMaster(0)("WORKADDR")) 'อาชีพ
            txtWorkPhone.Text = IIf(drCusMaster(0)("WORKPHONE") Is DBNull.Value, "", drCusMaster(0)("WORKPHONE")) 'อาชีพอื่นๆ
            txtWorkFax.Text = IIf(drCusMaster(0)("WORKFAX") Is DBNull.Value, "", drCusMaster(0)("WORKFAX"))
            txtContactAddr.Text = IIf(drCusMaster(0)("CONTACTADDR") Is DBNull.Value, "", drCusMaster(0)("CONTACTADDR"))
            txtContactPhone.Text = IIf(drCusMaster(0)("CONTACTPHONE") Is DBNull.Value, "", drCusMaster(0)("CONTACTPHONE"))
            txtContactFax.Text = IIf(drCusMaster(0)("CONTACTFAX") Is DBNull.Value, "", drCusMaster(0)("CONTACTFAX"))
            Try
                If Not (drCusMaster(0)("CUSTIDTYPE") Is Nothing Or drCusMaster(0)("CUSTIDTYPE") Is DBNull.Value) Then
                    ddlTranEV.SelectedValue = drCusMaster(0)("CUSTIDTYPE")
                Else
                    ddlTranEV.SelectedIndex = 0
                End If
            Catch ex As Exception

            End Try



            
            txtTranEVOther.Text = IIf(drCusMaster(0)("CUSTIDTYPEOTHER") Is DBNull.Value, "", drCusMaster(0)("CUSTIDTYPEOTHER"))
            txtEVNo.Text = IIf(drCusMaster(0)("CUSTID") Is DBNull.Value, "", drCusMaster(0)("CUSTID"))
            txtEVBy.Text = IIf(drCusMaster(0)("EVBY") Is DBNull.Value, "", drCusMaster(0)("EVBY"))
            'txtEvGen.Text = If(drCusMaster(0)("EVGen") Is DBNull.Value, If(drCusMaster(0)("EVGenText") Is DBNull.Value, "", drCusMaster(0)("EVGenText")), drCusMaster(0)("EVGenText"))
            txtEvGen.Text = If(drCusMaster(0)("EVGenText") Is DBNull.Value, "", drCusMaster(0)("EVGenText"))
            'txtEvExpire.Text = If(drCusMaster(0)("EVExpire") Is DBNull.Value, If(drCusMaster(0)("EVExpireText") Is DBNull.Value, "", drCusMaster(0)("EVGenText")), drCusMaster(0)("EVExpireText"))
            txtEvExpire.Text = If(drCusMaster(0)("EVExpireText") Is DBNull.Value, "", drCusMaster(0)("EVExpireText"))
            drCusMaster(0).Delete()
            dsAMLO.AcceptChanges()
            '--------------------------------------------------


            ' ส่วนที่ 3 -----------------------------------------

            txtTransDate.Text = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, tblAmlo(0).TRANSDATE)
            Try
                If Not (tblAmlo(0).TRANSTYPE Is Nothing Or tblAmlo(0).TRANSTYPE Is DBNull.Value) Then
                    ddlTransType.SelectedValue = tblAmlo(0).TRANSTYPE
                Else
                    ddlTransType.SelectedIndex = 0
                End If
            Catch ex As Exception

            End Try

            txtTransTypeOther.Text = tblAmlo(0).TRANSTYPEOTHER

            Try
                If Not (tblAmlo(0).ASSETTYPE Is Nothing Or tblAmlo(0).ASSETTYPE Is DBNull.Value) Then
                    ddlAsset.SelectedValue = tblAmlo(0).ASSETTYPE

                Else
                    ddlAsset.SelectedIndex = 0
                End If
            Catch ex As Exception

            End Try


            txtAssetOther.Text = tblAmlo(0).ASSETTYPEOTHER
            txtAssetDetail.Text = tblAmlo(0).ASSETTYPEDETAIL

            txtAccountNo.Text = tblAmlo(0).ACCOUNTNO
            txtAccountName.Text = tblAmlo(0).ACCOUNTNAME
            txtAccountOwnerPrefix.Text = tblAmlo(0).ACCPREFIX
            txtAccountOwnerfirstName.Text = tblAmlo(0).ACCFIRSTNAME
            txtAccountOwnerMidName.Text = tblAmlo(0).ACCMIDNAME
            txtAccountOwnerLastName.Text = tblAmlo(0).ACCLASTNAME

            txtAccountNoRef.Text = tblAmlo(0).ACCOUNTREF
            txtAccountNameRef.Text = tblAmlo(0).ACCOUNTREFNAME
            txtAccountRefPrefix.Text = tblAmlo(0).REFPREFIX
            txtAccountRefFirstName.Text = tblAmlo(0).REFFIRSTNAME
            txtAccountRefMidName.Text = tblAmlo(0).REFMIDNAME
            txtAccountRefLastName.Text = tblAmlo(0).REFLASTNAME

            Try
                If Not (tblAmlo(0).REFERENCETYPE Is Nothing Or tblAmlo(0).REFERENCETYPE Is DBNull.Value) Then
                    ddlRelation.SelectedValue = tblAmlo(0).REFERENCETYPE
                Else
                    ddlRelation.SelectedIndex = 0
                End If

            Catch ex As Exception

            End Try


            txtRelationOther.Text = tblAmlo(0).REFERENCETYPEOTHER

            txtCurrency.Text = tblAmlo(0).CURRENCY

            If Not (tblAmlo(0).TRANSAMT Is Nothing) Then
                txtTranAmt.Text = insertComma(tblAmlo(0).TRANSAMT)
            End If

            txtGainPrefix.Text = tblAmlo(0).GAINPREFIX
            txtGainFirstName.Text = tblAmlo(0).GAINFIRSTNAME
            txtGainMidName.Text = tblAmlo(0).GAINMIDNAME
            txtGainLastName.Text = tblAmlo(0).GAINLASTNAME
            Try
                If Not (tblAmlo(0).OBJBIZ Is Nothing Or tblAmlo(0).OBJBIZ Is DBNull.Value) Then
                    ddlObjName.SelectedValue = tblAmlo(0).OBJBIZ
                Else
                    ddlObjName.SelectedValue = 0
                End If
            Catch ex As Exception

            End Try



            txtObjOther.Text = tblAmlo(0).OBJBIZOTHER
            rdoSaveType.SelectedValue = tblAmlo(0).SAVETYPE
            txtSaveDate.Text = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, tblAmlo(0).SAVEDATE)

            rdoSignType.SelectedValue = tblAmlo(0).SIGNTYPE
            If (tblAmlo(0).ISCOMPLETE = 1) Then
                rdolIsComple.SelectedValue = tblAmlo(0).ISCOMPLETE
                rdolIsComple.Enabled = False
            Else
                rdolIsComple.SelectedValue = tblAmlo(0).ISCOMPLETE
            End If
            '--------------------------------------------------
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

#End Region

#Region " กรณี Add "

#Region " DataMaster "
    Private Function GetSOL_ID(ByVal branchCode As String) As String
        Return (From branch In AMLOEntity.SBRANCH Where branch.BRANCHCODE = branchCode Select branch.SOL_ID).SingleOrDefault
    End Function

    'ส่วนที่ 1
    Private Sub setTransaction(ByRef tblAmlo As AMLO102, ByVal intMaxID As Integer, ByVal strMaxRPTNo As String, ByVal isComplete As Integer)
        Try
            If (isComplete = 1) Then
                tblAmlo.RPTSEQ = intMaxID
                tblAmlo.GHBCODE = "033"
                tblAmlo.BRANCHCODE = ddlBranch.SelectedValue
                tblAmlo.SOL_ID = GetSOL_ID(ddlBranch.SelectedValue)
                tblAmlo.DEPTCODE = clsSessionMenuRight.getDeptCode
                tblAmlo.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight
                tblAmlo.ZONECODE = clsSessionMenuRight.getZoneCode
                tblAmlo.RPTYEAR = txtYear.Text
                tblAmlo.RPTNO = strMaxRPTNo
                tblAmlo.RPTTYPE = strRptType
                tblAmlo.RPTREV = txtRev.Text
                tblAmlo.RPTDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDate.Text)
            ElseIf (isComplete = 0) Then
                tblAmlo.RPTSEQ = intMaxID
                tblAmlo.GHBCODE = "033"
                tblAmlo.BRANCHCODE = ddlBranch.SelectedValue
                tblAmlo.SOL_ID = GetSOL_ID(ddlBranch.SelectedValue)
                tblAmlo.DEPTCODE = clsSessionMenuRight.getDeptCode
                tblAmlo.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight
                tblAmlo.ZONECODE = clsSessionMenuRight.getZoneCode
                tblAmlo.RPTYEAR = txtYear.Text
                tblAmlo.RPTNO = Nothing
                tblAmlo.RPTTYPE = strRptType
                tblAmlo.RPTREV = txtRev.Text
                tblAmlo.RPTDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDate.Text)
            End If
            tblAmlo.ISCREATEBY = 0 'คีย์ทางหน้าจอ

        Catch ex As Exception
            Throw ex
        End Try

    End Sub
    'ส่วนที่ 2
    Private Sub setCustomerSave()
        Try
            If Not (dsAMLO.Tables("AmloDetail").Select("RPTIDX=" & 1).Count = 1) Then
                Dim drrRPTDetail As DataRow = dsAMLO.Tables("AmloDetail").NewRow
                drrRPTDetail("RPTIDX") = 1
                If Not (ddlUniqueType.SelectedIndex = 0) Then
                    drrRPTDetail("UNIQUETYPE") = ddlUniqueType.SelectedValue
                End If
                If (rdolIsComple.SelectedValue = 0) Then
                    drrRPTDetail("UNIQUEID") = If(txtUniqueID.Text.Trim = "", "", txtUniqueID.Text.Trim)
                    drrRPTDetail("PreFix") = If(txtPrefix.Text.Trim = "", "", txtPrefix.Text.Trim)
                    drrRPTDetail("FirstName") = If(txtFirstName.Text.Trim = "", "", txtFirstName.Text.Trim)
                    drrRPTDetail("MidName") = If(txtMidName.Text.Trim = "", "", txtMidName.Text.Trim)
                    drrRPTDetail("LastName") = If(txtLastName.Text.Trim = "", "", txtLastName.Text.Trim)
                    drrRPTDetail("FORMALADDR") = If(txtFormalAddr.Text.Trim = "", "", txtFormalAddr.Text.Trim)
                    drrRPTDetail("FORMALPHONE") = If(txtFormalPhone.Text.Trim = "", "", txtFormalPhone.Text.Trim)
                    drrRPTDetail("FORMALFAX") = If(txtFormalFax.Text.Trim = "", "", txtFormalFax.Text.Trim)
                    If Not (ddlJob.SelectedIndex = 0) Then
                        drrRPTDetail("OccupationType") = ddlJob.SelectedValue 'อาชีพ
                    End If
                    drrRPTDetail("OccupationTypeOther") = If(txtWorkOther.Text.Trim = "", "", txtWorkOther.Text.Trim) 'อาชีพอื่นๆ
                    drrRPTDetail("WORKADDR") = If(txtWorkAddr.Text.Trim = "", "", txtWorkAddr.Text.Trim) 'อาชีพ
                    drrRPTDetail("WORKPHONE") = If(txtWorkPhone.Text.Trim = "", "", txtWorkPhone.Text.Trim) 'อาชีพอื่นๆ
                    drrRPTDetail("WORKFAX") = If(txtWorkFax.Text.Trim = "", "", txtWorkFax.Text.Trim)
                    drrRPTDetail("CONTACTADDR") = If(txtContactAddr.Text.Trim = "", "", txtContactAddr.Text.Trim)
                    drrRPTDetail("CONTACTPHONE") = If(txtContactPhone.Text.Trim = "", "", txtContactPhone.Text.Trim)
                    drrRPTDetail("CONTACTFAX") = If(txtContactFax.Text.Trim = "", "", txtContactFax.Text.Trim)
                    If Not (ddlTranEV.SelectedIndex = 0) Then
                        drrRPTDetail("CUSTIDTYPE") = ddlTranEV.SelectedValue
                    End If
                    drrRPTDetail("CUSTIDTYPEOTHER") = If(txtTranEVOther.Text.Trim = "", "", txtTranEVOther.Text.Trim)
                    drrRPTDetail("CUSTID") = If(txtEVNo.Text.Trim = "", "", txtEVNo.Text.Trim)
                    drrRPTDetail("EVBY") = If(txtEVBy.Text.Trim = "", "", txtEVBy.Text.Trim)
                    If Not (txtEvGen.Text.Trim = "") Then
                        If (txtEvGen.Text.Trim = "-") Then
                            drrRPTDetail("EVGenText") = "-"
                        Else
                            'drrRPTDetail("EVGen") = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.En, txtEvGen.Text)
                            drrRPTDetail("EVGenText") = txtEvGen.Text
                        End If

                    End If
                    If Not (txtEvExpire.Text.Trim = "") Then
                        If (txtEvExpire.Text.Trim = "-") Then
                            drrRPTDetail("EVExpireText") = "-"
                        Else
                            'drrRPTDetail("EVExpire") = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.En, txtEvExpire.Text)
                            drrRPTDetail("EVExpireText") = txtEvExpire.Text
                        End If
                    End If
                Else
                    drrRPTDetail("UNIQUEID") = If(txtUniqueID.Text.Trim = "", "-", txtUniqueID.Text.Trim)
                    drrRPTDetail("PreFix") = If(txtPrefix.Text.Trim = "", "-", txtPrefix.Text.Trim)
                    drrRPTDetail("FirstName") = If(txtFirstName.Text.Trim = "", "-", txtFirstName.Text.Trim)
                    drrRPTDetail("MidName") = If(txtMidName.Text.Trim = "", "-", txtMidName.Text.Trim)
                    drrRPTDetail("LastName") = If(txtLastName.Text.Trim = "", "-", txtLastName.Text.Trim)
                    drrRPTDetail("FORMALADDR") = If(txtFormalAddr.Text.Trim = "", "-", txtFormalAddr.Text.Trim)
                    drrRPTDetail("FORMALPHONE") = If(txtFormalPhone.Text.Trim = "", "-", txtFormalPhone.Text.Trim)
                    drrRPTDetail("FORMALFAX") = If(txtFormalFax.Text.Trim = "", "-", txtFormalFax.Text.Trim)
                    If Not (ddlJob.SelectedIndex = 0) Then
                        drrRPTDetail("OccupationType") = ddlJob.SelectedValue 'อาชีพ
                    End If
                    drrRPTDetail("OccupationTypeOther") = If(txtWorkOther.Text.Trim = "", "-", txtWorkOther.Text.Trim) 'อาชีพอื่นๆ
                    drrRPTDetail("WORKADDR") = If(txtWorkAddr.Text.Trim = "", "-", txtWorkAddr.Text.Trim) 'อาชีพ
                    drrRPTDetail("WORKPHONE") = If(txtWorkPhone.Text.Trim = "", "-", txtWorkPhone.Text.Trim) 'อาชีพอื่นๆ
                    drrRPTDetail("WORKFAX") = If(txtWorkFax.Text.Trim = "", "-", txtWorkFax.Text.Trim)
                    drrRPTDetail("CONTACTADDR") = If(txtContactAddr.Text.Trim = "", "-", txtContactAddr.Text.Trim)
                    drrRPTDetail("CONTACTPHONE") = If(txtContactPhone.Text.Trim = "", "-", txtContactPhone.Text.Trim)
                    drrRPTDetail("CONTACTFAX") = If(txtContactFax.Text.Trim = "", "-", txtContactFax.Text.Trim)
                    If Not (ddlTranEV.SelectedIndex = 0) Then
                        drrRPTDetail("CUSTIDTYPE") = ddlTranEV.SelectedValue
                    End If
                    drrRPTDetail("CUSTIDTYPEOTHER") = If(txtTranEVOther.Text.Trim = "", "-", txtTranEVOther.Text.Trim)
                    drrRPTDetail("CUSTID") = If(txtEVNo.Text.Trim = "", "-", txtEVNo.Text.Trim)
                    drrRPTDetail("EVBY") = If(txtEVBy.Text.Trim = "", "-", txtEVBy.Text.Trim)
                    If (txtEvGen.Text.Trim = "-") Then
                        drrRPTDetail("EVGenText") = "-"
                    Else
                        'drrRPTDetail("EVGen") = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.En, txtEvGen.Text)
                        drrRPTDetail("EVGenText") = txtEvGen.Text
                    End If

                    If (txtEvExpire.Text.Trim = "-") Then
                        drrRPTDetail("EVExpireText") = "-"
                    Else
                        'drrRPTDetail("EVExpire") = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.En, txtEvExpire.Text)
                        drrRPTDetail("EVExpireText") = txtEvExpire.Text
                    End If
                End If
                drrRPTDetail("CreateDate") = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, dteDateIsChk:=Date.Now)
                drrRPTDetail("CreateBy") = clsSessionMenuRight.getUserName
                dsAMLO.Tables("AmloDetail").Rows.Add(drrRPTDetail)

            End If


        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    'ส่วนที่ 3
    Public Sub SetDataFact(ByRef tblAMLO As AMLO102)
        Try

            If (rdolIsComple.SelectedValue = 0) Then

                tblAMLO.TRANSTYPEOTHER = If(txtTransTypeOther.Text.Trim = "", Nothing, txtTransTypeOther.Text.Trim)
                tblAMLO.ASSETTYPEOTHER = If(txtAssetOther.Text.Trim = "", Nothing, txtAssetOther.Text.Trim)
                tblAMLO.ASSETTYPEDETAIL = If(txtAssetDetail.Text.Trim = "", Nothing, txtAssetDetail.Text.Trim)

                tblAMLO.ACCOUNTNO = If(txtAccountNo.Text.Trim = "", Nothing, txtAccountNo.Text.Trim)
                tblAMLO.ACCOUNTNAME = If(txtAccountName.Text.Trim = "", Nothing, txtAccountName.Text.Trim)
                tblAMLO.ACCPREFIX = If(txtAccountOwnerPrefix.Text.Trim = "", Nothing, txtAccountOwnerPrefix.Text.Trim)
                tblAMLO.ACCFIRSTNAME = If(txtAccountOwnerfirstName.Text.Trim = "", Nothing, txtAccountOwnerfirstName.Text.Trim)
                tblAMLO.ACCMIDNAME = If(txtAccountOwnerMidName.Text.Trim = "", Nothing, txtAccountOwnerMidName.Text.Trim)
                tblAMLO.ACCLASTNAME = If(txtAccountOwnerLastName.Text.Trim = "", Nothing, txtAccountOwnerLastName.Text.Trim)

                tblAMLO.ACCOUNTREF = If(txtAccountNoRef.Text.Trim = "", Nothing, txtAccountNoRef.Text.Trim)
                tblAMLO.ACCOUNTREFNAME = If(txtAccountNameRef.Text.Trim = "", Nothing, txtAccountNameRef.Text.Trim)
                tblAMLO.REFPREFIX = If(txtAccountRefPrefix.Text.Trim = "", Nothing, txtAccountRefPrefix.Text.Trim)
                tblAMLO.REFFIRSTNAME = If(txtAccountRefFirstName.Text.Trim = "", Nothing, txtAccountRefFirstName.Text.Trim)
                tblAMLO.REFMIDNAME = If(txtAccountRefMidName.Text.Trim = "", Nothing, txtAccountRefMidName.Text.Trim)
                tblAMLO.REFLASTNAME = If(txtAccountRefLastName.Text.Trim = "", Nothing, txtAccountRefLastName.Text.Trim)
                tblAMLO.REFERENCETYPEOTHER = If(txtRelationOther.Text.Trim = "", Nothing, txtRelationOther.Text.Trim)

                tblAMLO.CURRENCY = If(txtCurrency.Text.Trim = "", Nothing, txtCurrency.Text.Trim)
                If (txtTranAmt.Text.Trim = "") Then
                    tblAMLO.TRANSAMT = Nothing
                Else
                    tblAMLO.TRANSAMT = deleteComma(txtTranAmt.Text)
                    tblAMLO.TRANSAMTCHAR = clsCurrencyTotext.ThaStrMoney(txtTranAmt.Text)
                End If
                tblAMLO.GAINPREFIX = If(txtGainPrefix.Text.Trim = "", Nothing, txtGainPrefix.Text.Trim)
                tblAMLO.GAINFIRSTNAME = If(txtGainFirstName.Text.Trim = "", Nothing, txtGainFirstName.Text.Trim)
                tblAMLO.GAINMIDNAME = If(txtGainMidName.Text.Trim = "", Nothing, txtGainMidName.Text.Trim)
                tblAMLO.GAINLASTNAME = If(txtGainLastName.Text.Trim = "", Nothing, txtGainLastName.Text.Trim)
                tblAMLO.OBJBIZOTHER = If(txtObjOther.Text.Trim = "", Nothing, txtObjOther.Text.Trim)

            Else


                tblAMLO.TRANSTYPEOTHER = If(txtTransTypeOther.Text.Trim = "", "-", txtTransTypeOther.Text.Trim)
                tblAMLO.ASSETTYPEOTHER = If(txtAssetOther.Text.Trim = "", "-", txtAssetOther.Text.Trim)
                tblAMLO.ASSETTYPEDETAIL = If(txtAssetDetail.Text.Trim = "", "-", txtAssetDetail.Text.Trim)

                tblAMLO.ACCOUNTNO = If(txtAccountNo.Text.Trim = "", "-", txtAccountNo.Text.Trim)
                tblAMLO.ACCOUNTNAME = If(txtAccountName.Text.Trim = "", "-", txtAccountName.Text.Trim)
                tblAMLO.ACCPREFIX = If(txtAccountOwnerPrefix.Text.Trim = "", "-", txtAccountOwnerPrefix.Text.Trim)
                tblAMLO.ACCFIRSTNAME = If(txtAccountOwnerfirstName.Text.Trim = "", "-", txtAccountOwnerfirstName.Text.Trim)
                tblAMLO.ACCMIDNAME = If(txtAccountOwnerMidName.Text.Trim = "", "-", txtAccountOwnerMidName.Text.Trim)
                tblAMLO.ACCLASTNAME = If(txtAccountOwnerLastName.Text.Trim = "", "-", txtAccountOwnerLastName.Text.Trim)

                tblAMLO.ACCOUNTNO = If(txtAccountNo.Text.Trim = "", "-", txtAccountNo.Text.Trim)
                tblAMLO.ACCOUNTNAME = If(txtAccountName.Text.Trim = "", "-", txtAccountName.Text.Trim)
                tblAMLO.ACCPREFIX = If(txtAccountOwnerPrefix.Text.Trim = "", "-", txtAccountOwnerPrefix.Text.Trim)
                tblAMLO.ACCFIRSTNAME = If(txtAccountOwnerfirstName.Text.Trim = "", "-", txtAccountOwnerfirstName.Text.Trim)
                tblAMLO.ACCMIDNAME = If(txtAccountOwnerMidName.Text.Trim = "", "-", txtAccountOwnerMidName.Text.Trim)
                tblAMLO.ACCLASTNAME = If(txtAccountOwnerLastName.Text.Trim = "", "-", txtAccountOwnerLastName.Text.Trim)

                tblAMLO.ACCOUNTREF = If(txtAccountNoRef.Text.Trim = "", "-", txtAccountNoRef.Text.Trim)
                tblAMLO.ACCOUNTREFNAME = If(txtAccountNameRef.Text.Trim = "", "-", txtAccountNameRef.Text.Trim)
                tblAMLO.REFPREFIX = If(txtAccountRefPrefix.Text.Trim = "", "-", txtAccountRefPrefix.Text.Trim)
                tblAMLO.REFFIRSTNAME = If(txtAccountRefFirstName.Text.Trim = "", "-", txtAccountRefFirstName.Text.Trim)
                tblAMLO.REFMIDNAME = If(txtAccountRefMidName.Text.Trim = "", "-", txtAccountRefMidName.Text.Trim)
                tblAMLO.REFLASTNAME = If(txtAccountRefLastName.Text.Trim = "", "-", txtAccountRefLastName.Text.Trim)
                tblAMLO.REFERENCETYPEOTHER = If(txtRelationOther.Text.Trim = "", "-", txtRelationOther.Text.Trim)

                tblAMLO.CURRENCY = If(txtCurrency.Text.Trim = "", "-", txtCurrency.Text.Trim)
                If (txtTranAmt.Text.Trim = "") Then
                    tblAMLO.TRANSAMT = 0
                Else
                    tblAMLO.TRANSAMT = deleteComma(txtTranAmt.Text)
                    tblAMLO.TRANSAMTCHAR = clsCurrencyTotext.ThaStrMoney(txtTranAmt.Text)
                End If


                tblAMLO.GAINPREFIX = If(txtGainPrefix.Text.Trim = "", "-", txtGainPrefix.Text.Trim)
                tblAMLO.GAINFIRSTNAME = If(txtGainFirstName.Text.Trim = "", "-", txtGainFirstName.Text.Trim)
                tblAMLO.GAINMIDNAME = If(txtGainMidName.Text.Trim = "", "-", txtGainMidName.Text.Trim)
                tblAMLO.GAINLASTNAME = If(txtGainLastName.Text.Trim = "", "-", txtGainLastName.Text.Trim)
                tblAMLO.OBJBIZOTHER = If(txtObjOther.Text.Trim = "", "-", txtObjOther.Text.Trim)
            End If

            tblAMLO.TRANSDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtTransDate.Text)
            If Not (ddlTransType.SelectedIndex = 0) Then
                tblAMLO.TRANSTYPE = ddlTransType.SelectedValue '2
            End If

            If Not (ddlAsset.SelectedIndex = 0) Then
                tblAMLO.ASSETTYPE = ddlAsset.SelectedValue
            End If

            If Not (ddlRelation.SelectedIndex = 0) Then
                tblAMLO.REFERENCETYPE = ddlRelation.SelectedValue
            End If

            If Not (ddlObjName.SelectedIndex = 0) Then
                tblAMLO.OBJBIZ = ddlObjName.SelectedValue
            End If


            tblAMLO.SAVETYPE = rdoSaveType.SelectedValue
            tblAMLO.SAVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtSaveDate.Text)

            tblAMLO.SIGNTYPE = rdoSignType.SelectedValue

            tblAMLO.ISCOMPLETE = rdolIsComple.SelectedValue


            'If (rdolIsComple.SelectedValue = 1) Then
            tblAMLO.ISSEND = 0
            'End If
            tblAMLO.ISDELETE = 0
            tblAMLO.ISCONFIRM = 0
            tblAMLO.ISSENDCONFIRM = 0
            tblAMLO.CREATEBY = clsSessionMenuRight.getUserName
            tblAMLO.CREATEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, dteDateIsChk:=Date.Now)
            tblAMLO.UPDATEBY = clsSessionMenuRight.getUserName
            tblAMLO.UPDATEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, dteDateIsChk:=Date.Now)

            clsCurrencyTotext = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region

#Region " DataDetail "
    'ส่วนที่ 2 
    Private Sub SetPartnerTrans(ByVal AMLOEnt As AMLO102Entities, ByVal tblrAmloDetail As AMLODETAIL102, ByVal intMaxID As Integer)
        Dim intCountItem As Integer = 0
        intCountItem = dsAMLO.Tables("AmloDetail").Rows.Count
        Dim intRptIndex As Integer = 0

        Try
            For i As Integer = 0 To intCountItem - 1
                tblrAmloDetail = New AMLODETAIL102

                tblrAmloDetail.RPTSEQ = intMaxID
                tblrAmloDetail.RPTIDX = CInt(dsAMLO.Tables("AmloDetail").Rows(i)("RPTIDX"))
                intRptIndex = CInt(dsAMLO.Tables("AmloDetail").Rows(i)("RPTIDX"))
                'If (intCountItem > 1) Then
                If (intRptIndex = 1) Then
                    Dim dr As DataRow() = dsAMLO.Tables("AmloDetail").Select("RPTIDX=" & 2)
                    If Not (dr.Length = 0) Then
                        If (dr(0)("RPTIDXTYPE") = 1) Then
                            tblrAmloDetail.RPTIDXTYPE = 1
                        Else
                            tblrAmloDetail.RPTIDXTYPE = 2
                        End If
                    Else
                        tblrAmloDetail.RPTIDXTYPE = 1
                    End If


                    dr = Nothing
                Else
                    tblrAmloDetail.RPTIDXTYPE = CInt(dsAMLO.Tables("AmloDetail").Rows(i)("RPTIDXTYPE"))
                End If
                'Else
                '    tblrAmloDetail.RPTIDXTYPE = 1
                'End If





                If Not (dsAMLO.Tables("AmloDetail").Rows(i)("UNIQUETYPE") Is DBNull.Value) Then
                    tblrAmloDetail.UNIQUETYPE = CInt(dsAMLO.Tables("AmloDetail").Rows(i)("UNIQUETYPE"))
                End If
                tblrAmloDetail.UNIQUEID = dsAMLO.Tables("AmloDetail").Rows(i)("UNIQUEID")
                tblrAmloDetail.PREFIX = dsAMLO.Tables("AmloDetail").Rows(i)("PREFIX")

                tblrAmloDetail.FIRSTNAME = dsAMLO.Tables("AmloDetail").Rows(i)("FIRSTNAME")
                tblrAmloDetail.MIDNAME = dsAMLO.Tables("AmloDetail").Rows(i)("MIDNAME")
                tblrAmloDetail.LASTNAME = dsAMLO.Tables("AmloDetail").Rows(i)("LASTNAME")
                tblrAmloDetail.FORMALADDR = dsAMLO.Tables("AmloDetail").Rows(i)("FORMALADDR")
                tblrAmloDetail.FORMALPHONE = dsAMLO.Tables("AmloDetail").Rows(i)("FORMALPHONE")

                tblrAmloDetail.FORMALFAX = dsAMLO.Tables("AmloDetail").Rows(i)("FORMALFAX")

                If Not (dsAMLO.Tables("AmloDetail").Rows(i)("OCCUPATIONTYPE") Is DBNull.Value) Then
                    tblrAmloDetail.OCCUPATIONTYPE = dsAMLO.Tables("AmloDetail").Rows(i)("OCCUPATIONTYPE")
                End If

                tblrAmloDetail.OCCUPATIONTYPEOTHER = dsAMLO.Tables("AmloDetail").Rows(i)("OCCUPATIONTYPEOTHER")
                tblrAmloDetail.WORKADDR = dsAMLO.Tables("AmloDetail").Rows(i)("WORKADDR")
                tblrAmloDetail.WORKPHONE = dsAMLO.Tables("AmloDetail").Rows(i)("WORKPHONE")
                tblrAmloDetail.WORKFAX = dsAMLO.Tables("AmloDetail").Rows(i)("WORKFAX")

                If Not (dsAMLO.Tables("AmloDetail").Rows(i)("BIZTYPE") Is DBNull.Value) Then
                    tblrAmloDetail.BIZTYPE = dsAMLO.Tables("AmloDetail").Rows(i)("biztype")
                End If

                If Not (dsAMLO.Tables("AmloDetail").Rows(i)("BIZTYPEOTHER") Is DBNull.Value) Then
                    tblrAmloDetail.BIZTYPEOTHER = dsAMLO.Tables("AmloDetail").Rows(i)("BIZTYPEOTHER")
                End If

                tblrAmloDetail.CONTACTADDR = dsAMLO.Tables("AmloDetail").Rows(i)("CONTACTADDR")
                tblrAmloDetail.CONTACTPHONE = dsAMLO.Tables("AmloDetail").Rows(i)("CONTACTPHONE")
                tblrAmloDetail.CONTACTFAX = dsAMLO.Tables("AmloDetail").Rows(i)("CONTACTFAX")

                If Not (dsAMLO.Tables("AmloDetail").Rows(i)("CUSTIDTYPE") Is DBNull.Value) Then
                    tblrAmloDetail.CUSTIDTYPE = dsAMLO.Tables("AmloDetail").Rows(i)("CUSTIDTYPE")
                End If

                tblrAmloDetail.CUSTIDTYPEOTHER = dsAMLO.Tables("AmloDetail").Rows(i)("CUSTIDTYPEOTHER")
                tblrAmloDetail.CUSTID = dsAMLO.Tables("AmloDetail").Rows(i)("CUSTID")

                tblrAmloDetail.EVBY = dsAMLO.Tables("AmloDetail").Rows(i)("EVBY")
                'If Not (dsAMLO.Tables("AmloDetail").Rows(i)("EVGEN") Is DBNull.Value) Then
                '    tblrAmloDetail.EVGEN = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, _
                '                                                       dsAMLO.Tables("AmloDetail").Rows(i)("EVGEN"))
                'End If
                If Not (dsAMLO.Tables("AmloDetail").Rows(i)("EVGENTEXT") Is DBNull.Value) Then
                    tblrAmloDetail.EVGENTEXT = dsAMLO.Tables("AmloDetail").Rows(i)("EVGENTEXT")

                End If

                'If Not (dsAMLO.Tables("AmloDetail").Rows(i)("EVEXPIRE") Is DBNull.Value) Then
                '    tblrAmloDetail.EVEXPIRE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, _
                '                                                          dsAMLO.Tables("AmloDetail").Rows(i)("EVEXPIRE"))
                'End If
                If Not (dsAMLO.Tables("AmloDetail").Rows(i)("EVEXPIRETEXT") Is DBNull.Value) Then
                    tblrAmloDetail.EVEXPIRETEXT = dsAMLO.Tables("AmloDetail").Rows(i)("EVEXPIRETEXT")
                End If

                tblrAmloDetail.CREATEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, _
                                                                        dsAMLO.Tables("AmloDetail").Rows(i)("CREATEDATE"))

                tblrAmloDetail.CREATEBY = dsAMLO.Tables("AmloDetail").Rows(i)("CREATEBY")
                AMLOEnt.AddToAMLODETAIL102(tblrAmloDetail)
                tblrAmloDetail = Nothing

            Next
        Catch ex As Exception
            Dim dr As DataRow() = dsAMLO.Tables("AmloDetail").Select("RPTIDX=" & 1)
            dr(0).Delete()
            dsAMLO.AcceptChanges()
            Throw (ex)
        End Try

    End Sub
#End Region

#End Region

#Region " กรณี Edit "

#Region " DataMaster "
    'ส่วนที่ 1
    Private Sub setTransaction(ByRef tblRRPT As IList(Of AMLO102), ByVal strMaxNo As String)
        Try
            tblRRPT(0).GHBCODE = "033"
            tblRRPT(0).BRANCHCODE = ddlBranch.SelectedValue
            tblRRPT(0).SOL_ID = GetSOL_ID(ddlBranch.SelectedValue)
            tblRRPT(0).RPTYEAR = txtYear.Text
            If (rdolIsComple.SelectedValue = 1) And (rdolIsComple.Enabled = True) Then
                tblRRPT(0).RPTNO = strMaxNo
            End If

            If (tblRRPT(0).ISSEND = True) Then
                tblRRPT(0).RPTREV = tblRRPT(0).RPTREV + 1
            Else
                tblRRPT(0).RPTREV = txtRev.Text
            End If


        Catch ex As Exception
            Throw ex
        End Try

    End Sub
    'ส่วนที่ 2
    Private Sub setCustomer(ByRef tblAmloDetail As IList(Of AMLODETAIL102))
        Try
            If Not (dsAMLO.Tables("AmloDetail").Rows.Count = 0) Then
                Dim dr As DataRow() = dsAMLO.Tables("AmloDetail").Select("RPTIDX=" & 2)
                If (dr(0)("RPTIDXTYPE") = 1) Then
                    tblAmloDetail(0).RPTIDXTYPE = 1
                Else
                    tblAmloDetail(0).RPTIDXTYPE = 2
                End If
                dr = Nothing
            Else
                tblAmloDetail(0).RPTIDXTYPE = 1
            End If
            
            If (rdolIsComple.SelectedValue = 0) Then
                If Not (ddlUniqueType.SelectedIndex = 0) Then
                    tblAmloDetail(0).UNIQUETYPE = ddlUniqueType.SelectedValue
                End If
                tblAmloDetail(0).UNIQUEID = If(txtUniqueID.Text.Trim = "", "", txtUniqueID.Text.Trim)
                tblAmloDetail(0).PREFIX = If(txtPrefix.Text.Trim = "", "", txtPrefix.Text.Trim)
                tblAmloDetail(0).FIRSTNAME = If(txtFirstName.Text.Trim = "", "", txtFirstName.Text.Trim)
                tblAmloDetail(0).MIDNAME = If(txtMidName.Text.Trim = "", "", txtMidName.Text.Trim)
                tblAmloDetail(0).LASTNAME = If(txtLastName.Text.Trim = "", "", txtLastName.Text.Trim)
                tblAmloDetail(0).FORMALADDR = If(txtFormalAddr.Text.Trim = "", "", txtFormalAddr.Text.Trim)
                tblAmloDetail(0).FORMALPHONE = If(txtFormalPhone.Text.Trim = "", "", txtFormalPhone.Text.Trim)
                tblAmloDetail(0).FORMALFAX = If(txtFormalFax.Text.Trim = "", "", txtFormalFax.Text.Trim)
                If Not (ddlJob.SelectedIndex = 0) Then
                    tblAmloDetail(0).OCCUPATIONTYPE = ddlJob.SelectedValue 'อาชีพ
                End If
                tblAmloDetail(0).OCCUPATIONTYPEOTHER = If(txtWorkOther.Text.Trim = "", "", txtWorkOther.Text.Trim) 'อาชีพอื่นๆ
                tblAmloDetail(0).WORKADDR = If(txtWorkAddr.Text.Trim = "", "", txtWorkAddr.Text.Trim) 'อาชีพ
                tblAmloDetail(0).WORKPHONE = If(txtWorkPhone.Text.Trim = "", "", txtWorkPhone.Text.Trim) 'อาชีพอื่นๆ
                tblAmloDetail(0).WORKFAX = If(txtWorkFax.Text.Trim = "", "", txtWorkFax.Text.Trim)
                tblAmloDetail(0).CONTACTADDR = If(txtContactAddr.Text.Trim = "", "", txtContactAddr.Text.Trim)
                tblAmloDetail(0).CONTACTPHONE = If(txtContactPhone.Text.Trim = "", "", txtContactPhone.Text.Trim)
                tblAmloDetail(0).CONTACTFAX = If(txtContactFax.Text.Trim = "", "", txtContactFax.Text.Trim)
                If Not (ddlTranEV.SelectedIndex = 0) Then
                    tblAmloDetail(0).CUSTIDTYPE = ddlTranEV.SelectedValue
                End If
                tblAmloDetail(0).CUSTIDTYPEOTHER = If(txtTranEVOther.Text.Trim = "", "", txtTranEVOther.Text.Trim)
                tblAmloDetail(0).CUSTID = If(txtEVNo.Text.Trim = "", "", txtEVNo.Text.Trim)
                tblAmloDetail(0).EVBY = If(txtEVBy.Text.Trim = "", "", txtEVBy.Text.Trim)
                If Not (txtEvGen.Text.Trim = "") Then
                    If (txtEvGen.Text.Trim = "-") Then
                        tblAmloDetail(0).EVGENTEXT = "-"
                    Else
                        ' tblAmloDetail(0).EVGEN = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.En, txtEvGen.Text)
                        tblAmloDetail(0).EVGENTEXT = txtEvGen.Text
                    End If

                End If
                If Not (txtEvExpire.Text.Trim = "") Then
                    If (txtEvExpire.Text.Trim = "-") Then
                        tblAmloDetail(0).EVEXPIRETEXT = "-"
                    Else
                        'tblAmloDetail(0).EVEXPIRE = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.En, txtEvExpire.Text)
                        tblAmloDetail(0).EVEXPIRETEXT = txtEvExpire.Text
                    End If

                End If

            Else
                tblAmloDetail(0).UNIQUETYPE = ddlUniqueType.SelectedValue
                tblAmloDetail(0).UNIQUEID = If(txtUniqueID.Text.Trim = "", "-", txtUniqueID.Text.Trim)
                tblAmloDetail(0).PREFIX = If(txtPrefix.Text.Trim = "", "-", txtPrefix.Text.Trim)
                tblAmloDetail(0).FIRSTNAME = If(txtFirstName.Text.Trim = "", "-", txtFirstName.Text.Trim)
                tblAmloDetail(0).MIDNAME = If(txtMidName.Text.Trim = "", "-", txtMidName.Text.Trim)
                tblAmloDetail(0).LASTNAME = If(txtLastName.Text.Trim = "", "-", txtLastName.Text.Trim)
                tblAmloDetail(0).FORMALADDR = If(txtFormalAddr.Text.Trim = "", "-", txtFormalAddr.Text.Trim)
                tblAmloDetail(0).FORMALPHONE = If(txtFormalPhone.Text.Trim = "", "-", txtFormalPhone.Text.Trim)
                tblAmloDetail(0).FORMALFAX = If(txtFormalFax.Text.Trim = "", "-", txtFormalFax.Text.Trim)
                If Not (ddlJob.SelectedIndex = 0) Then
                    tblAmloDetail(0).OCCUPATIONTYPE = ddlJob.SelectedValue 'อาชีพ
                End If
                tblAmloDetail(0).OCCUPATIONTYPEOTHER = If(txtWorkOther.Text.Trim = "", "-", txtWorkOther.Text.Trim) 'อาชีพอื่นๆ
                tblAmloDetail(0).WORKADDR = If(txtWorkAddr.Text.Trim = "", "-", txtWorkAddr.Text.Trim) 'อาชีพ
                tblAmloDetail(0).WORKPHONE = If(txtWorkPhone.Text.Trim = "", "-", txtWorkPhone.Text.Trim) 'อาชีพอื่นๆ
                tblAmloDetail(0).WORKFAX = If(txtWorkFax.Text.Trim = "", "-", txtWorkFax.Text.Trim)
                tblAmloDetail(0).CONTACTADDR = If(txtContactAddr.Text.Trim = "", "-", txtContactAddr.Text.Trim)
                tblAmloDetail(0).CONTACTPHONE = If(txtContactPhone.Text.Trim = "", "-", txtContactPhone.Text.Trim)
                tblAmloDetail(0).CONTACTFAX = If(txtContactFax.Text.Trim = "", "-", txtContactFax.Text.Trim)
                tblAmloDetail(0).CUSTIDTYPE = ddlTranEV.SelectedValue
                tblAmloDetail(0).CUSTIDTYPEOTHER = If(txtTranEVOther.Text.Trim = "", "-", txtTranEVOther.Text.Trim)
                tblAmloDetail(0).CUSTID = If(txtEVNo.Text.Trim = "", "-", txtEVNo.Text.Trim)
                tblAmloDetail(0).EVBY = If(txtEVBy.Text.Trim = "", "-", txtEVBy.Text.Trim)
                If (txtEvGen.Text.Trim = "-") Then
                    tblAmloDetail(0).EVGENTEXT = "-"
                Else
                    'tblAmloDetail(0).EVGEN = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.En, txtEvGen.Text)
                    tblAmloDetail(0).EVGENTEXT = txtEvGen.Text
                End If

                If (txtEvExpire.Text.Trim = "-") Then
                    tblAmloDetail(0).EVEXPIRETEXT = "-"
                Else
                    'tblAmloDetail(0).EVEXPIRE = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.En, txtEvExpire.Text)
                    tblAmloDetail(0).EVEXPIRETEXT = txtEvExpire.Text
                End If

            End If

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    'ส่วนที่ 3

    Public Sub SetDataFact_Edit(ByRef tblAmlo As IList(Of AMLO102))
        Try

            '------------------------------------------------------------------------------
            If (rdolIsComple.SelectedValue = 0) Then

                tblAmlo(0).TRANSTYPEOTHER = If(txtTransTypeOther.Text.Trim = "", Nothing, txtTransTypeOther.Text.Trim)

                tblAmlo(0).ASSETTYPEOTHER = If(txtAssetOther.Text.Trim = "", Nothing, txtAssetOther.Text.Trim)
                tblAmlo(0).ASSETTYPEDETAIL = If(txtAssetDetail.Text.Trim = "", Nothing, txtAssetDetail.Text.Trim)

                tblAmlo(0).ACCOUNTNO = If(txtAccountNo.Text.Trim = "", Nothing, txtAccountNo.Text.Trim)
                tblAmlo(0).ACCOUNTNAME = If(txtAccountName.Text.Trim = "", Nothing, txtAccountName.Text.Trim)
                tblAmlo(0).ACCPREFIX = If(txtAccountOwnerPrefix.Text.Trim = "", Nothing, txtAccountOwnerPrefix.Text.Trim)
                tblAmlo(0).ACCFIRSTNAME = If(txtAccountOwnerfirstName.Text.Trim = "", Nothing, txtAccountOwnerfirstName.Text.Trim)
                tblAmlo(0).ACCMIDNAME = If(txtAccountOwnerMidName.Text.Trim = "", Nothing, txtAccountOwnerMidName.Text.Trim)
                tblAmlo(0).ACCLASTNAME = If(txtAccountOwnerLastName.Text.Trim = "", Nothing, txtAccountOwnerLastName.Text.Trim)

                tblAmlo(0).ACCOUNTREF = If(txtAccountNoRef.Text.Trim = "", Nothing, txtAccountNoRef.Text.Trim)
                tblAmlo(0).ACCOUNTREFNAME = If(txtAccountNameRef.Text.Trim = "", Nothing, txtAccountNameRef.Text.Trim)
                tblAmlo(0).REFPREFIX = If(txtAccountRefPrefix.Text.Trim = "", Nothing, txtAccountRefPrefix.Text.Trim)
                tblAmlo(0).REFFIRSTNAME = If(txtAccountRefFirstName.Text.Trim = "", Nothing, txtAccountRefFirstName.Text.Trim)
                tblAmlo(0).REFMIDNAME = If(txtAccountRefMidName.Text.Trim = "", Nothing, txtAccountRefMidName.Text.Trim)
                tblAmlo(0).REFLASTNAME = If(txtAccountRefLastName.Text.Trim = "", Nothing, txtAccountRefLastName.Text.Trim)

                tblAmlo(0).REFERENCETYPEOTHER = If(txtRelationOther.Text.Trim = "", Nothing, txtRelationOther.Text.Trim)


                tblAmlo(0).CURRENCY = If(txtCurrency.Text.Trim = "", Nothing, txtCurrency.Text.Trim)
                If (txtTranAmt.Text.Trim = "") Then
                    tblAmlo(0).TRANSAMT = Nothing
                Else
                    tblAmlo(0).TRANSAMT = deleteComma(txtTranAmt.Text)
                    tblAmlo(0).TRANSAMTCHAR = clsCurrencyTotext.ThaStrMoney(txtTranAmt.Text)
                End If
                tblAmlo(0).GAINPREFIX = If(txtGainPrefix.Text.Trim = "", Nothing, txtGainPrefix.Text.Trim)
                tblAmlo(0).GAINFIRSTNAME = If(txtGainFirstName.Text.Trim = "", Nothing, txtGainFirstName.Text.Trim)
                tblAmlo(0).GAINMIDNAME = If(txtGainMidName.Text.Trim = "", Nothing, txtGainMidName.Text.Trim)
                tblAmlo(0).GAINLASTNAME = If(txtGainLastName.Text.Trim = "", Nothing, txtGainLastName.Text.Trim)
                tblAmlo(0).OBJBIZOTHER = If(txtObjOther.Text.Trim = "", Nothing, txtObjOther.Text.Trim)


            Else

                tblAmlo(0).TRANSTYPEOTHER = If(txtTransTypeOther.Text.Trim = "", "-", txtTransTypeOther.Text.Trim)

                tblAmlo(0).ASSETTYPEOTHER = If(txtAssetOther.Text.Trim = "", "-", txtAssetOther.Text.Trim)
                tblAmlo(0).ASSETTYPEDETAIL = If(txtAssetDetail.Text.Trim = "", "-", txtAssetDetail.Text.Trim)

                tblAmlo(0).ACCOUNTNO = If(txtAccountNo.Text.Trim = "", "-", txtAccountNo.Text.Trim)
                tblAmlo(0).ACCOUNTNAME = If(txtAccountName.Text.Trim = "", "-", txtAccountName.Text.Trim)
                tblAmlo(0).ACCPREFIX = If(txtAccountOwnerPrefix.Text.Trim = "", "-", txtAccountOwnerPrefix.Text.Trim)
                tblAmlo(0).ACCFIRSTNAME = If(txtAccountOwnerfirstName.Text.Trim = "", "-", txtAccountOwnerfirstName.Text.Trim)
                tblAmlo(0).ACCMIDNAME = If(txtAccountOwnerMidName.Text.Trim = "", "-", txtAccountOwnerMidName.Text.Trim)
                tblAmlo(0).ACCLASTNAME = If(txtAccountOwnerLastName.Text.Trim = "", "-", txtAccountOwnerLastName.Text.Trim)

                tblAmlo(0).ACCOUNTREF = If(txtAccountNoRef.Text.Trim = "", "-", txtAccountNoRef.Text.Trim)
                tblAmlo(0).ACCOUNTREFNAME = If(txtAccountNameRef.Text.Trim = "", "-", txtAccountNameRef.Text.Trim)
                tblAmlo(0).REFPREFIX = If(txtAccountRefPrefix.Text.Trim = "", "-", txtAccountRefPrefix.Text.Trim)
                tblAmlo(0).REFFIRSTNAME = If(txtAccountRefFirstName.Text.Trim = "", "-", txtAccountRefFirstName.Text.Trim)
                tblAmlo(0).REFMIDNAME = If(txtAccountRefMidName.Text.Trim = "", "-", txtAccountRefMidName.Text.Trim)
                tblAmlo(0).REFLASTNAME = If(txtAccountRefLastName.Text.Trim = "", "-", txtAccountRefLastName.Text.Trim)

                tblAmlo(0).REFERENCETYPEOTHER = txtRelationOther.Text

                tblAmlo(0).CURRENCY = If(txtCurrency.Text.Trim = "", "-", txtCurrency.Text.Trim)
                If (txtTranAmt.Text.Trim = "") Then
                    tblAmlo(0).TRANSAMT = 0
                Else
                    tblAmlo(0).TRANSAMT = deleteComma(txtTranAmt.Text)
                    tblAmlo(0).TRANSAMTCHAR = clsCurrencyTotext.ThaStrMoney(txtTranAmt.Text)
                End If
                'tblAmlo(0).TRANSAMT = If(txtTranAmt.Text.Trim = "", 0, deleteComma(txtTranAmt.Text))
                tblAmlo(0).GAINPREFIX = If(txtGainPrefix.Text.Trim = "", "-", txtGainPrefix.Text.Trim)
                tblAmlo(0).GAINFIRSTNAME = If(txtGainFirstName.Text.Trim = "", "-", txtGainFirstName.Text.Trim)
                tblAmlo(0).GAINMIDNAME = If(txtGainMidName.Text.Trim = "", "-", txtGainMidName.Text.Trim)
                tblAmlo(0).GAINLASTNAME = If(txtGainLastName.Text.Trim = "", "-", txtGainLastName.Text.Trim)

                tblAmlo(0).OBJBIZOTHER = If(txtObjOther.Text.Trim = "", "-", txtObjOther.Text.Trim)
            End If
            tblAmlo(0).TRANSDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtTransDate.Text)

            If Not (ddlTransType.SelectedIndex = 0) Then
                tblAmlo(0).TRANSTYPE = ddlTransType.SelectedValue '2
            Else
                tblAmlo(0).TRANSTYPE = Nothing
            End If
            If Not (ddlAsset.SelectedIndex = 0) Then
                tblAmlo(0).ASSETTYPE = ddlAsset.SelectedValue
            Else
                tblAmlo(0).ASSETTYPE = Nothing
            End If
            If Not (ddlRelation.SelectedIndex = 0) Then
                tblAmlo(0).REFERENCETYPE = ddlRelation.SelectedValue
            Else
                tblAmlo(0).REFERENCETYPE = Nothing
            End If
            If Not (ddlObjName.SelectedIndex = 0) Then
                tblAmlo(0).OBJBIZ = ddlObjName.SelectedValue '12
            Else
                tblAmlo(0).OBJBIZ = Nothing
            End If

            tblAmlo(0).SAVETYPE = rdoSaveType.SelectedValue '14
            tblAmlo(0).SAVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtSaveDate.Text)
            tblAmlo(0).SIGNTYPE = rdoSignType.SelectedValue
            tblAmlo(0).ISCOMPLETE = rdolIsComple.SelectedValue

            If (rdolIsComple.SelectedValue = 1) Then
                If (tblAmlo(0).ISSEND = True) Then
                    tblAmlo(0).ISSEND = False
                Else
                    tblAmlo(0).ISSEND = False
                End If
            End If

            tblAmlo(0).UPDATEBY = clsSessionMenuRight.getUserName
            tblAmlo(0).UPDATEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtSaveDate.Text)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region

#End Region



#Region " Even Grid "

    Private Sub clearGvIndex()
        grdShowCountry.SelectedIndex = -1
        btnEdit.Attributes.Clear()
    End Sub

    Protected Sub grdShowCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdShowCountry.SelectedIndexChanged
        If (grdShowCountry.SelectedIndex = intBeforeItemIndex) Then
            grdShowCountry.SelectedIndex = -1
            clearGvIndex()
        Else
             blnStatusComplete = False
            Try

                BindingData(grdShowCountry.SelectedIndex)
                setbtnpart2("Modify")
                blnStatusComplete = True
            Catch ex As Exception
                blnStatusComplete = False
                strError = "Error Message :" & If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
            End Try
            If Not (blnStatusComplete) Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                   UpdatePanel1.GetType(), _
                                                                   "clientScript", _
                                                                   "alert('" + strError.Replace("'", "") + "')", _
                                                                   True)
            End If
        End If
    End Sub

    Protected Sub grdShowCountry_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdShowCountry.SelectedIndexChanging
        intBeforeItemIndex = grdShowCountry.SelectedIndex
    End Sub

#End Region

#Region "ส่วนที่ 2"

    Public Sub SetDataCustomerPartTwo(Optional ByVal tblmCus As IList(Of MCUSTOMER) = Nothing, _
                             Optional ByVal tblAmloDetail As IList(Of AMLODETAIL102) = Nothing)
        clsFormatDate = New clsDateFormat
        If Not (tblmCus Is Nothing) Then
            txtPrefix.Text = tblmCus(0).THPREFIX
            txtFirstName.Text = tblmCus(0).THFIRSTNAME
            txtMidName.Text = tblmCus(0).THMIDNAME
            txtLastName.Text = tblmCus(0).THLASTNAME
            txtFormalAddr.Text = tblmCus(0).FORMALADDR
            txtFormalPhone.Text = tblmCus(0).FORMALPHONE1
            txtFormalFax.Text = tblmCus(0).FORMALFAX
            ddlJob.SelectedValue = tblmCus(0).OCCUPATIONTYPE1
            txtWorkOther.Text = tblmCus(0).OCCUPATIONTYPEOTHER1
            txtWorkAddr.Text = tblmCus(0).WORKADDR
            txtWorkPhone.Text = tblmCus(0).WORKPHONE1
            txtWorkFax.Text = tblmCus(0).WORKFAX
            txtContactAddr.Text = tblmCus(0).CONTACTADDR
            txtContactPhone.Text = tblmCus(0).CONTACTPHONE1
            txtContactFax.Text = tblmCus(0).CONTACTFAX
            txtEVNo.Text = tblmCus(0).CUSTID
            txtEVBy.Text = tblmCus(0).EVBY
            If Not (tblmCus(0).EVGEN Is Nothing) Then
                txtEvGen.Text = clsFormatDate.convertDateToInt(clsDateFormat.enmDateCultureInfo.Th, dteDate:=tblmCus(0).EVGEN)

            End If

            If Not (tblmCus(0).EVEXPIRE Is Nothing) Then
                txtEvExpire.Text = clsFormatDate.convertDateToInt(clsDateFormat.enmDateCultureInfo.Th, dteDate:=tblmCus(0).EVEXPIRE)
            End If

        ElseIf Not (tblAmloDetail Is Nothing) Then
            txtPrefix.Text = tblAmloDetail(0).PREFIX
            txtFirstName.Text = tblAmloDetail(0).FIRSTNAME
            txtMidName.Text = tblAmloDetail(0).MIDNAME
            txtLastName.Text = tblAmloDetail(0).LASTNAME
            txtFormalAddr.Text = tblAmloDetail(0).FORMALADDR
            txtFormalPhone.Text = tblAmloDetail(0).FORMALPHONE
            txtFormalFax.Text = tblAmloDetail(0).FORMALFAX
            ddlJob.SelectedValue = tblAmloDetail(0).OCCUPATIONTYPE
            txtWorkOther.Text = tblAmloDetail(0).OCCUPATIONTYPEOTHER
            txtWorkAddr.Text = tblAmloDetail(0).WORKADDR
            txtWorkPhone.Text = tblAmloDetail(0).WORKPHONE
            txtWorkFax.Text = tblAmloDetail(0).WORKFAX
            txtContactAddr.Text = tblAmloDetail(0).CONTACTADDR
            txtContactPhone.Text = tblAmloDetail(0).CONTACTPHONE
            txtContactFax.Text = tblAmloDetail(0).CONTACTFAX
            ddlTranEV.SelectedValue = tblAmloDetail(0).CUSTIDTYPE
            txtTranEVOther.Text = tblAmloDetail(0).CUSTIDTYPEOTHER
            txtEVNo.Text = tblAmloDetail(0).CUSTID
            txtEVBy.Text = tblAmloDetail(0).EVBY
            If Not (tblAmloDetail(0).EVGEN Is Nothing) Then
                txtEvGen.Text = (clsFormatDate.convertDateToInt(clsDateFormat.enmDateCultureInfo.Th, dteDate:=tblAmloDetail(0).EVGEN))

            End If

            If Not (tblAmloDetail(0).EVEXPIRE Is Nothing) Then
                txtEvExpire.Text = clsFormatDate.convertDateToInt(clsDateFormat.enmDateCultureInfo.Th, dteDate:=tblAmloDetail(0).EVEXPIRE)
            End If
        End If

    End Sub

    Sub BindingData(ByVal intIndex As Integer)
        'Dim drAmlo As DataRow() = dsAMLO.Tables("RRPTDETAIL").Select("RPTIDX = " & index)


        'clsFormatDate = New clsDateFormat
        'ddlUniqueType0.SelectedValue = drAmlo(0)("UniqueType")
        'txtUniqueID0.Text = drAmlo(0)("UniqueID")
        'txtPrefix0.Text = drAmlo(0)("PreFix")
        'txtFirstName0.Text = drAmlo(0)("FirstName")
        'txtMidName0.Text = drAmlo(0)("MidName")
        'txtLastName0.Text = drAmlo(0)("LastName")
        'txtFormalAddr0.Text = drAmlo(0)("FORMALADDR")
        'txtFormalPhone0.Text = drAmlo(0)("FORMALPHONE")
        'txtFormalFax0.Text = drAmlo(0)("FORMALFAX")
        'ddlJob0.SelectedValue = drAmlo(0)("OccupationType")
        'txtWorkOther0.Text = drAmlo(0)("OccupationTypeOther")
        'txtWorkAddr0.Text = drAmlo(0)("WORKADDR")
        'txtWorkPhone0.Text = drAmlo(0)("WORKPHONE")
        'txtWorkFax0.Text = drAmlo(0)("WORKFAX")
        'txtContactAddr0.Text = drAmlo(0)("CONTACTADDR")
        'txtContactPhone0.Text = drAmlo(0)("CONTACTPHONE")
        'txtContactFax0.Text = drAmlo(0)("CONTACTFAX")
        'ddlTranEV0.SelectedValue = drAmlo(0)("CUSTIDTYPE")
        'txtTranEVOther0.Text = drAmlo(0)("CUSTIDTYPEOTHER")
        'txtEVNo0.Text = drAmlo(0)("CUSTID")
        'txtEVBy0.Text = drAmlo(0)("EVBY")

        'If Not (drAmlo(0)("EVGEN") Is Nothing) Then
        '    txtEvGen0.Text = clsFormatDate.convertDateToInt(clsDateFormat.enmDateCultureInfo.Th, dteDate:=drAmlo(0)("EVGEN"))
        'End If
        'If Not (drAmlo(0)("EVEXPIRE") Is Nothing) Then
        '    txtEvExpire0.Text = clsFormatDate.convertDateToInt(clsDateFormat.enmDateCultureInfo.Th, dteDate:=drAmlo(0)("EVEXPIRE"))
        'End If
        clsFormatDate = New clsDateFormat
        hdfRptIdx.Value = dsAMLO.Tables("AmloDetail").Rows(intIndex)("RPTIDX")
        hdfUniqueID_Part2.Value = dsAMLO.Tables("AmloDetail").Rows(intIndex)("UniqueID")
        Try
            If Not (dsAMLO.Tables("AmloDetail").Rows(intIndex)("RPTIDXType") Is Nothing Or dsAMLO.Tables("AmloDetail").Rows(intIndex)("RPTIDXType") Is DBNull.Value) Then
                ddlIdxType.SelectedValue = dsAMLO.Tables("AmloDetail").Rows(intIndex)("RPTIDXType")
            Else
                ddlIdxType.SelectedIndex = 0
            End If
        Catch ex As Exception

        End Try

        Try
            If Not (dsAMLO.Tables("AmloDetail").Rows(intIndex)("UniqueType") Is Nothing Or dsAMLO.Tables("AmloDetail").Rows(intIndex)("UniqueType") Is DBNull.Value) Then
                ddlUniqueType0.SelectedValue = dsAMLO.Tables("AmloDetail").Rows(intIndex)("UniqueType")
            Else
                ddlUniqueType0.SelectedIndex = 0
            End If
        Catch ex As Exception

        End Try


        txtUniqueID0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("UniqueID")
        txtPrefix0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("PreFix")
        txtFirstName0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("FirstName")
        txtMidName0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("MidName")
        txtLastName0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("LastName")
        txtFormalAddr0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("FORMALADDR")
        txtFormalPhone0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("FORMALPHONE")
        txtFormalFax0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("FORMALFAX")
        If Not (dsAMLO.Tables("AmloDetail").Rows(intIndex)("OccupationType") Is Nothing Or dsAMLO.Tables("AmloDetail").Rows(intIndex)("OccupationType") Is DBNull.Value) Then
            ddlJob0.SelectedValue = dsAMLO.Tables("AmloDetail").Rows(intIndex)("OccupationType")
        Else
            ddlJob0.SelectedIndex = 0
        End If
        txtWorkOther0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("OccupationTypeOther")
        txtWorkAddr0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("WORKADDR")
        txtWorkPhone0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("WORKPHONE")
        txtWorkFax0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("WORKFAX")
        Try
            If Not (dsAMLO.Tables("AmloDetail").Rows(intIndex)("BIZTYPE") Is DBNull.Value Or dsAMLO.Tables("AmloDetail").Rows(intIndex)("BIZTYPE") Is Nothing) Then
                ddlBizType.SelectedValue = dsAMLO.Tables("AmloDetail").Rows(intIndex)("BIZTYPE")
            Else
                ddlBizType.SelectedIndex = 0
            End If
        Catch ex As Exception

        End Try


        txtBizTypeOther.Text = IIf(dsAMLO.Tables("AmloDetail").Rows(intIndex)("BIZTYPEOTHER") Is DBNull.Value, "", dsAMLO.Tables("AmloDetail").Rows(intIndex)("BIZTYPEOTHER"))

        txtContactAddr0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("CONTACTADDR")

        txtContactPhone0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("CONTACTPHONE")
        txtContactFax0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("CONTACTFAX")
        Try
            If Not (dsAMLO.Tables("AmloDetail").Rows(intIndex)("CUSTIDTYPE") Is DBNull.Value Or dsAMLO.Tables("AmloDetail").Rows(intIndex)("CUSTIDTYPE") Is Nothing) Then
                ddlTranEV0.SelectedValue = dsAMLO.Tables("AmloDetail").Rows(intIndex)("CUSTIDTYPE")
            Else
                ddlTranEV0.SelectedIndex = 0
            End If

        Catch ex As Exception

        End Try


        txtTranEVOther0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("CUSTIDTYPEOTHER")
        txtEVNo0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("CUSTID")
        txtEVBy0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("EVBY")
        txtEvGen0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("EVGENTEXT")
        'If Not (dsAMLO.Tables("AmloDetail").Rows(intIndex)("EVGEN") Is Nothing) Then
        '    txtEvGen0.Text = clsFormatDate.convertDateToInt(clsDateFormat.enmDateCultureInfo.Th, dteDate:=dsAMLO.Tables("AmloDetail").Rows(intIndex)("EVGEN"))
        'End If
        txtEvExpire0.Text = dsAMLO.Tables("AmloDetail").Rows(intIndex)("EVEXPIRETEXT")
        'If Not (dsAMLO.Tables("AmloDetail").Rows(intIndex)("EVEXPIRE") Is Nothing) Then
        '    txtEvExpire0.Text = clsFormatDate.convertDateToInt(clsDateFormat.enmDateCultureInfo.Th, dteDate:=dsAMLO.Tables("AmloDetail").Rows(intIndex)("EVEXPIRE"))
        'End If
        clsFormatDate = Nothing
    End Sub

    Private Sub saveData()
        clsFormatDate = New clsDateFormat
        clsSessionMenuRight = New clsSessionMenuRight

        Try
            Dim intCount As Integer = dsAMLO.Tables("AmloDetail").Rows.Count

            Dim drrRPTDetail As DataRow = dsAMLO.Tables("AmloDetail").NewRow
            If intCount = 0 Then
                drrRPTDetail("RPTIDX") = 2
            Else
                Dim MaxRptIdx = (From ds_RrptDetail In dsAMLO.Tables("AmloDetail") Select ds_RrptDetail.Item("RPTIDX")).Max
                Dim intMax As Integer = MaxRptIdx + 1
                drrRPTDetail("RPTIDX") = intMax  'รหัสลูกค้า
            End If
            '------
            If Not (ddlIdxType.SelectedIndex = 0) Then
                drrRPTDetail("rptidxType") = ddlIdxType.SelectedValue
            End If
            If Not (ddlUniqueType0.SelectedIndex) Then
                drrRPTDetail("UniqueType") = ddlUniqueType0.SelectedValue
            End If
            '-------
            drrRPTDetail("UniqueID") = If(txtUniqueID0.Text.Trim = "", "-", txtUniqueID0.Text.Trim)
            drrRPTDetail("PreFix") = If(txtPrefix0.Text.Trim = "", "-", txtPrefix0.Text.Trim)
            drrRPTDetail("FirstName") = If(txtFirstName0.Text.Trim = "", "-", txtFirstName0.Text.Trim)
            drrRPTDetail("MidName") = If(txtMidName0.Text.Trim = "", "-", txtMidName0.Text.Trim)
            drrRPTDetail("LastName") = If(txtLastName0.Text.Trim = "", "-", txtLastName0.Text.Trim)
            drrRPTDetail("FORMALADDR") = If(txtFormalAddr0.Text.Trim = "", "-", txtFormalAddr0.Text.Trim)
            drrRPTDetail("FORMALPHONE") = If(txtFormalPhone0.Text.Trim = "", "-", txtFormalPhone0.Text.Trim)
            drrRPTDetail("FORMALFAX") = If(txtFormalFax0.Text.Trim = "", "-", txtFormalFax0.Text.Trim)
            '------
            If Not (ddlJob0.SelectedIndex = 0) Then
                drrRPTDetail("OccupationType") = ddlJob0.SelectedValue 'อาชีพ 
            End If
            '------
            drrRPTDetail("OccupationTypeOther") = If(txtWorkOther0.Text.Trim = "", "-", txtWorkOther0.Text.Trim) 'อาชีพอื่นๆ
            drrRPTDetail("WORKADDR") = If(txtWorkAddr0.Text.Trim = "", "-", txtWorkAddr0.Text.Trim)
            drrRPTDetail("WORKPHONE") = If(txtWorkPhone0.Text.Trim = "", "-", txtWorkPhone0.Text.Trim)
            drrRPTDetail("WORKFAX") = If(txtWorkFax0.Text.Trim = "", "-", txtWorkFax0.Text.Trim)
            '-----
            If Not (ddlBizType.SelectedIndex = 0) Then
                drrRPTDetail("BIZTYPE") = ddlBizType.SelectedValue
            End If


            drrRPTDetail("BIZTYPEOTHER") = If(txtBizTypeOther.Text.Trim = "", "-", txtBizTypeOther.Text.Trim)
            drrRPTDetail("CONTACTADDR") = If(txtContactAddr0.Text.Trim = "", "-", txtContactAddr0.Text.Trim)
            drrRPTDetail("CONTACTPHONE") = If(txtContactPhone0.Text.Trim = "", "-", txtContactPhone0.Text.Trim)
            drrRPTDetail("CONTACTFAX") = If(txtContactFax0.Text.Trim = "", "-", txtContactFax0.Text.Trim)
            '------
            If Not (ddlTranEV0.SelectedIndex = 0) Then
                drrRPTDetail("CUSTIDTYPE") = ddlTranEV0.SelectedValue
            End If

            drrRPTDetail("CUSTIDTYPEOTHER") = If(txtTranEVOther0.Text.Trim = "", "-", txtTranEVOther0.Text.Trim)
            drrRPTDetail("CUSTID") = If(txtEVNo0.Text.Trim = "", "-", txtEVNo0.Text.Trim)
            drrRPTDetail("EVBY") = If(txtEVBy0.Text.Trim = "", "-", txtEVBy0.Text.Trim)
            If (txtEvGen0.Text.Trim = "-") Then
                drrRPTDetail("EVGenText") = "-"
            Else
                'drrRPTDetail("EVGen") = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.Th, txtEvGen0.Text)
                drrRPTDetail("EVGenText") = txtEvGen0.Text.Trim
            End If

            If (txtEvExpire0.Text.Trim = "-") Then
                drrRPTDetail("EVExpireText") = "-"
            Else
                'drrRPTDetail("EVExpire") = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.Th, txtEvExpire0.Text)
                drrRPTDetail("EVExpireText") = txtEvExpire0.Text.Trim
            End If



            drrRPTDetail("CreateDate") = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, dteDateIsChk:=Date.Now)

            clsSessionMenuRight = Session("ClsMenuRight")
            drrRPTDetail("CreateBy") = clsSessionMenuRight.getUserName

            dsAMLO.Tables("AmloDetail").Rows.Add(drrRPTDetail)
            dsAMLO.Tables("AmloDetail").AcceptChanges()
        Catch ex As Exception
            Throw ex
        End Try


        clsFormatDate = Nothing
        clsSessionMenuRight = Nothing

    End Sub

    Sub updateData(ByVal index As Integer)
        clsFormatDate = New clsDateFormat
        clsSessionMenuRight = New clsSessionMenuRight
        Try
            Dim drAmlo As DataRow() = dsAMLO.Tables("AmloDetail").Select("RPTIDX = " & index)

            drAmlo(0)("rptidxType") = ddlIdxType.SelectedValue
            drAmlo(0)("UniqueType") = ddlUniqueType0.SelectedValue
            drAmlo(0)("UniqueID") = If(txtUniqueID0.Text.Trim = "", "-", txtUniqueID0.Text.Trim)
            drAmlo(0)("PreFix") = If(txtPrefix0.Text.Trim = "", "-", txtPrefix0.Text.Trim)
            drAmlo(0)("FirstName") = If(txtFirstName0.Text.Trim = "", "-", txtFirstName0.Text.Trim)
            drAmlo(0)("MidName") = If(txtMidName0.Text.Trim = "", "-", txtMidName0.Text.Trim)
            drAmlo(0)("LastName") = If(txtLastName0.Text.Trim = "", "-", txtLastName0.Text.Trim)
            If Not (ddlJob0.SelectedValue = 0) Then
                drAmlo(0)("OccupationType") = ddlJob0.SelectedValue
            Else
                drAmlo(0)("OccupationType") = DBNull.Value
            End If
            drAmlo(0)("OccupationTypeOther") = If(txtWorkOther0.Text.Trim = "", "-", txtWorkOther0.Text.Trim)
            drAmlo(0)("FORMALADDR") = If(txtFormalAddr0.Text.Trim = "", "-", txtFormalAddr0.Text.Trim)
            drAmlo(0)("FORMALPHONE") = If(txtFormalPhone0.Text.Trim = "", "-", txtFormalPhone0.Text.Trim)
            drAmlo(0)("FORMALFAX") = If(txtFormalFax0.Text.Trim = "", "-", txtFormalFax0.Text.Trim)
            drAmlo(0)("WORKADDR") = If(txtWorkAddr0.Text.Trim = "", "-", txtWorkAddr0.Text.Trim)
            drAmlo(0)("WORKPHONE") = If(txtWorkPhone0.Text.Trim = "", "-", txtWorkPhone0.Text.Trim)
            drAmlo(0)("WORKFAX") = If(txtWorkFax0.Text.Trim = "", "-", txtWorkFax0.Text.Trim)
            If Not (ddlBizType.SelectedValue = 0) Then
                drAmlo(0)("BIZTYPE") = ddlBizType.SelectedValue
            Else
                drAmlo(0)("BIZTYPE") = DBNull.Value

            End If
            drAmlo(0)("BIZTYPEOTHER") = If(txtBizTypeOther.Text.Trim = "", "-", txtBizTypeOther.Text.Trim)
            drAmlo(0)("CONTACTADDR") = If(txtContactAddr0.Text.Trim = "", "-", txtContactAddr0.Text.Trim)
            drAmlo(0)("CONTACTPHONE") = If(txtContactPhone0.Text.Trim = "", "-", txtContactPhone0.Text.Trim)
            drAmlo(0)("CONTACTFAX") = If(txtContactFax0.Text.Trim = "", "-", txtContactFax0.Text.Trim)

            drAmlo(0)("EVBY") = txtEVBy0.Text

            ' drAmlo(0)("EVGen") = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.En, txtEvGen0.Text)

            If (txtEvGen0.Text.Trim = "-") Then
                drAmlo(0)("EVGenText") = "-"
            Else
                ' drAmlo(0)("EVGen") = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.Th, txtEvGen0.Text)
                drAmlo(0)("EVGenText") = txtEvGen0.Text.Trim
            End If
            If (txtEvExpire0.Text.Trim = "-") Then
                drAmlo(0)("EVExpireText") = "-"
            Else
                ' drAmlo(0)("EVExpire") = clsFormatDate.convertIntToDate(clsDateFormat.enmDateCultureInfo.Th, txtEvExpire0.Text)
                drAmlo(0)("EVExpireText") = txtEvExpire0.Text.Trim
            End If

            drAmlo(0)("updateDate") = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, dteDateIsChk:=Date.Now)

            drAmlo(0)("CUSTIDTYPE") = ddlTranEV0.SelectedValue
            drAmlo(0)("CUSTIDTYPEOTHER") = If(txtTranEVOther0.Text.Trim = "", "-", txtTranEVOther0.Text.Trim)
            drAmlo(0)("CUSTID") = If(txtEVNo0.Text.Trim = "", "-", txtEVNo0.Text.Trim)
            clsSessionMenuRight = Session("ClsMenuRight")
            drAmlo(0)("updateBy") = clsSessionMenuRight.getUserName

            dsAMLO.Tables("AmloDetail").AcceptChanges()
            drAmlo = Nothing

        Catch ex As Exception
            Throw ex
        End Try
        clsSessionMenuRight = Nothing
        clsFormatDate = Nothing
    End Sub


#End Region

    Private Sub clearDataPart(ByVal enmPart As enmPartSearch, Optional ByVal strStatus As String = "")

        If (enmPart = enmPartSearch.part1) Then
            txtPrefix.Text = ""
            txtFirstName.Text = ""
            txtMidName.Text = ""
            txtLastName.Text = ""
            txtFormalAddr.Text = ""
            txtFormalPhone.Text = ""
            txtFormalFax.Text = ""
            ddlJob.SelectedValue = 0
            txtWorkOther.Text = ""
            txtWorkAddr.Text = ""
            txtWorkPhone.Text = ""
            txtWorkFax.Text = ""
            txtContactAddr.Text = ""
            txtContactPhone.Text = ""
            txtContactFax.Text = ""
            ddlTranEV.SelectedIndex = 0
            txtTranEVOther.Text = ""
            txtEVNo.Text = ""
            txtEVBy.Text = ""
            txtEvGen.Text = ""
            txtEvExpire.Text = ""

        ElseIf (enmPart = enmPartSearch.part2) Then
            If (strStatus = "") Then
                hdfUniqueID_Part2.Value = Nothing
                ddlUniqueType0.SelectedValue = 0
                txtUniqueID0.Text = ""
                ddlIdxType.SelectedIndex = 0
                ddlTranEV0.SelectedValue = 0
                txtTranEVOther0.Text = ""
                txtEVNo0.Text = ""
                txtEVBy0.Text = ""
                txtEvGen0.Text = ""
                txtEvExpire0.Text = ""
            End If

            txtPrefix0.Text = ""
            txtFirstName0.Text = ""
            txtMidName0.Text = ""
            txtLastName0.Text = ""
            txtFormalAddr0.Text = ""
            txtFormalPhone0.Text = ""
            txtFormalFax0.Text = ""
            ddlJob0.SelectedValue = 0
            txtWorkOther0.Text = ""
            txtWorkAddr0.Text = ""
            txtWorkPhone0.Text = ""
            txtWorkFax0.Text = ""
            ddlBizType.SelectedValue = 0
            txtBizTypeOther.Text = ""
            txtContactAddr0.Text = ""
            txtContactPhone0.Text = ""
            txtContactFax0.Text = ""
            ddlTranEV0.SelectedValue = 0
            txtTranEVOther0.Text = ""
            txtEVNo0.Text = ""
            txtEVBy0.Text = ""
            txtEvGen0.Text = ""
            txtEvExpire0.Text = ""
        End If

    End Sub
   

    Private Sub setbtnpart2(ByVal strStatus As String)
        If (strStatus = "Add") Then
            btnAdd.Visible = True
            btnEdit.Visible = False
            btnDelete.Visible = False

        ElseIf (strStatus = "Modify") Then
            btnAdd.Visible = False
            btnEdit.Visible = True
            btnDelete.Visible = True

        ElseIf (strStatus = "Delete") Then
            btnAdd.Visible = False
            btnEdit.Visible = True
            btnDelete.Visible = True
        ElseIf (strStatus = "Clear") Then
            btnAdd.Visible = True
            btnEdit.Visible = False
            btnDelete.Visible = False
        Else
            btnAdd.Visible = True
            btnEdit.Visible = False
            btnDelete.Visible = False

        End If

    End Sub

    'Protected Sub LinkButton1_Command1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
    '    btnAdd.Visible = False
    '    btnEdit.Visible = True
    '    btnDelete.Visible = True
    '    blnStatusComplete = False
    '    Try
    '        BindingData(e.CommandName)
    '        hdfRptIdx.Value = e.CommandName
    '        blnStatusComplete = True
    '    Catch ex As Exception
    '        blnStatusComplete = False
    '        strError = "Error Message :" & If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
    '    End Try
    '    If Not (blnStatusComplete) Then
    '        ScriptManager.RegisterStartupScript(UpdatePanel1, _
    '                                                           UpdatePanel1.GetType(), _
    '                                                           "clientScript", _
    '                                                           "alert('" + strError.Replace("'", "") + "')", _
    '                                                           True)
    '    End If

    'End Sub

    Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        clearDataPart(enmPartSearch.part2)
        setbtnpart2("")
        grdShowCountry.SelectedIndex = -1
    End Sub

    Protected Sub btnSearchData0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchData0.Click
        blnStatusComplete = False
        Try

            If Not (searchCustomer(txtUniqueID0.Text.Trim, enmPartSearch.part2)) Then
                clearDataPart(enmPartSearch.part2, "search")
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                                  UpdatePanel1.GetType(), _
                                                                  "clientScript", _
                                                                  "alert('" + "ไม่พบข้อมูลในระบบ" + "')", _
                                                                  True)

            End If

            blnStatusComplete = True
        Catch ex As Exception
            blnStatusComplete = False
            strError = "Error Message :" & If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
        End Try
        If Not (blnStatusComplete) Then
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                               UpdatePanel1.GetType(), _
                                                               "clientScript", _
                                                               "alert('" + strError.Replace("'", "") + "')", _
                                                               True)
        End If
    End Sub

    Protected Sub txtTranAmt_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTranAmt.TextChanged
        Dim blnStatusComplete As Boolean = False
        Try
            txtTranAmt.Text = insertComma(txtTranAmt.Text)
            txtAccountNo.Focus()
            blnStatusComplete = True
        Catch ex As Exception
            blnStatusComplete = False
            strError = "Error Message :" & If(ex.InnerException Is Nothing, ex.Message, ex.InnerException.Message)
            txtTranAmt.Focus()
            txtTranAmt.Text = ""

        End Try

        If Not (blnStatusComplete) Then
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                               UpdatePanel1.GetType(), _
                                                               "clientScript", _
                                                               "alert('" + strError.Replace("'", "") + "')", _
                                                               True)
        End If

    End Sub

    Private Function insertComma(ByVal strTransAmt As String) As String
        Dim dcmMoney As Decimal
        Try
            dcmMoney = strTransAmt
            strTransAmt = Decimal.Parse(strTransAmt).ToString("N2")
        Catch ex As Exception
            Throw ex
        End Try
        Return strTransAmt
    End Function

    Private Function deleteComma(ByVal strTransAmt As String) As String
        Dim dcmMoney As Decimal
        Try
            dcmMoney = strTransAmt
            strTransAmt = dcmMoney
        Catch ex As Exception
            Throw ex
        End Try
        Return strTransAmt
    End Function

    Private Function chkDataTransAmt(ByVal strTransAmt As String) As Boolean
        Dim ckktranAmt As Boolean = False
        Dim dcmMoney As Decimal
        Try
            dcmMoney = strTransAmt
            ckktranAmt = True
        Catch ex As Exception
            ckktranAmt = False
            'Throw ex
        End Try
        Return ckktranAmt
    End Function
    Private Function chkDataTransAmtMore(ByVal strTransAmt As String) As Boolean
        Dim ckktranAmt As Boolean = False
        Dim dcmMoney As Decimal
        Try
            dcmMoney = strTransAmt
            If (dcmMoney > 4999999.99) Then
                ckktranAmt = True
            Else
                ckktranAmt = False
            End If

        Catch ex As Exception
            ckktranAmt = False
            'Throw ex
        End Try
        Return ckktranAmt
    End Function

    Private Function chkIDcard(ByVal strIDCard As String) As Boolean
        Dim Sum, Count As Integer
        Dim blnStatus As Boolean = False


        Sum = 0
        For Count = 1 To 12
            Sum = Sum + Val(Mid(strIDCard, Count, 1)) * (14 - Count)
        Next

        If Microsoft.VisualBasic.Right(strIDCard, 1) = Microsoft.VisualBasic.Right(Str(11 - (Sum Mod 11)), 1) Then

            blnStatus = True
        Else

            blnStatus = False
        End If
        Return blnStatus
    End Function
    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("SearchAmlo1_02.aspx")
    End Sub
    Protected Sub ddlUniqueType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlUniqueType.SelectedIndexChanged
       
        Try
            setTextLength(ddlUniqueType, txtUniqueID)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub ddlUniqueType0_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlUniqueType0.SelectedIndexChanged
        Try
            setTextLength(ddlUniqueType0, txtUniqueID0)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try


    End Sub

    Public Sub setTextLength(ByVal ddlDropdownlist As DropDownList, ByVal txtTextBox As TextBox)
        Try
            If (ddlDropdownlist.SelectedValue = 1) Then
                txtTextBox.MaxLength = 13
                txtTextBox.Focus()
                If Not (txtTextBox.Text.Length = 0) Then
                    txtTextBox.Text = txtTextBox.Text.Substring(0, IIf(txtTextBox.Text.Length > 13, 13, txtTextBox.Text.Length))
                End If
            ElseIf (ddlDropdownlist.SelectedValue = 2 Or ddlDropdownlist.SelectedValue = 3) Then
                txtTextBox.MaxLength = 10
                txtTextBox.Focus()
                If Not (txtTextBox.Text.Length = 0) Then
                    txtTextBox.Text = txtTextBox.Text.Substring(0, IIf(txtTextBox.Text.Length > 10, 10, txtTextBox.Text.Length))
                End If
            ElseIf (ddlDropdownlist.SelectedValue = 9 Or ddlDropdownlist.SelectedValue = 99) Then
                txtTextBox.MaxLength = 20
                txtTextBox.Focus()
            Else
                txtTextBox.MaxLength = 20
                txtTextBox.Focus()
            End If
        Catch ex As Exception
            Throw ex
        End Try

    End Sub



    Protected Sub btnFormalToWork_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFormalToWork.Click
        txtWorkAddr.Text = txtFormalAddr.Text
        txtWorkPhone.Text = txtFormalPhone.Text
        txtWorkFax.Text = txtFormalFax.Text

    End Sub
    Protected Sub btnFormalToContact_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFormalToContact.Click
        txtContactAddr.Text = txtFormalAddr.Text
        txtContactPhone.Text = txtFormalPhone.Text
        txtContactFax.Text = txtFormalFax.Text
    End Sub
    Protected Sub btnWorkToContact_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnWorkToContact.Click
        txtContactAddr.Text = txtWorkAddr.Text
        txtContactPhone.Text = txtWorkPhone.Text
        txtContactFax.Text = txtWorkFax.Text
    End Sub

    Protected Sub btnFormalToWork0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFormalToWork0.Click
        txtWorkAddr0.Text = txtFormalAddr0.Text
        txtWorkPhone0.Text = txtFormalPhone0.Text
        txtWorkFax0.Text = txtFormalFax0.Text
    End Sub

    Protected Sub btnFormalToContact0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFormalToContact0.Click
        txtContactAddr0.Text = txtFormalAddr0.Text
        txtContactPhone0.Text = txtFormalPhone0.Text
        txtContactFax0.Text = txtFormalFax0.Text
    End Sub

    Protected Sub btnWorkToContact0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnWorkToContact0.Click
        txtContactAddr0.Text = txtWorkAddr0.Text
        txtContactPhone0.Text = txtWorkPhone0.Text
        txtContactFax0.Text = txtWorkFax0.Text
    End Sub

    
    Protected Sub ddlTranEV0_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTranEV0.SelectedIndexChanged
        Try
            If (CInt(ddlUniqueType0.SelectedValue) = CInt(ddlTranEV0.SelectedValue)) Then
                txtEVNo0.Text = txtUniqueID0.Text
            Else
                txtEVNo0.Text = ""
            End If
            setTextLength(ddlTranEV0, txtEVNo0)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub ddlTranEV_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTranEV.SelectedIndexChanged
        Try
            If (CInt(ddlUniqueType.SelectedValue) = CInt(ddlTranEV.SelectedValue)) Then
                txtEVNo.Text = txtUniqueID.Text
            Else
                txtEVNo.Text = ""
            End If
            setTextLength(ddlTranEV, txtEVNo)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub txtTransDate_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTransDate.TextChanged
        Try
            Dim strDate As String = Nothing
            strDate = txtTransDate.Text.Split("/")(2)
            txtYear.Text = strDate.Substring(2, 2)
        Catch ex As Exception

        End Try
    End Sub

End Class
